I simply don't get! #define -
Baltazar - 12.04.2015
This simple code:
Код:
#include <a_samp>
#if defined printf
#undef printf
#endif
main(){
}
Doesn't compile! Why!?
It seems like this line
finds printf to be defined and tries to execute this line
but compiler emits error on this as it doesn't recognize printf as defined anymore... wtf? Explain me please
Re: I simply don't get! #define -
Vince - 12.04.2015
You can't simply "undefine" just anything. The manual says:
Quote:
#undef name
Removes a text substitution macro or a numeric constant declared
with const. The “name” parameter must be the macro “prefix”
—the alphanumeric part of the macro. See page 93 for details and
examples on text substitution.
|
Re: I simply don't get! #define -
Baltazar - 12.04.2015
Quote:
Originally Posted by Vince
You can't simply "undefine" just anything. The manual says:
|
Ok, thanks; I got it. Here is one more:
Код:
#include <a_samp>
#define _FIRST print
main(){
_FIRSTf("%s", "Test string");
}
Here is my understanting:
Pre-compiler meets #define. From now on it searches for any instance of "_FIRST" and replaces it with "print". Just like a human being would do it using text replacement tool.
But:
It doesn't work this exact way and throws an error about "_FIRSTf" being not defined. How does it work then? Sometimes it replaces chunks of code, sometimes it doesn't.
Re: I simply don't get! #define -
Crayder - 12.04.2015
- CUT -
The predecessor searches only for whole words.
To do _FIRSTf
You need to #define _FIRSTf printf
Re: I simply don't get! #define -
Baltazar - 12.04.2015
Quote:
Originally Posted by Crayder
This line, #undef printf, undefined the printf. So it will not be defined, it's pretty self explanatory.
|
It doesn't. Compiler throws an error, that such a constant "printf" doesn't exist and thus can't be undefined.
Re: I simply don't get! #define -
Crayder - 12.04.2015
Quote:
Originally Posted by Baltazar
It doesn't. Compiler throws an error, that such a constant "printf" doesn't exist and thus can't be undefined.
|
printf is not a constant in the script. So it is correct. It's a native function.
Re: I simply don't get! #define -
Baltazar - 12.04.2015
Quote:
Originally Posted by Crayder
printf is not a constant in the script. So it is correct. It's a native function.
|
But well, this line
finds "printf" to be defined although it's not a constant. Anyway, you are right and I kind of got it
Re: I simply don't get! #define -
Threshold - 12.04.2015
Works fine for me.
Код:
doesn't exist and thus can't be undefined.
Those are two different things. They either exist and are defined, or do not exist and are undefined. You can't have both.
Re: I simply don't get! #define -
Crayder - 12.04.2015
Quote:
Originally Posted by Baltazar
finds "printf" to be defined although it's not a constant. Anyway, you are right and I kind of got it
|
Aha, I don't think I'm right completely. I think I should take another look at the manual, you should as well.
http://www.compuphase.com/pawn/Pawn_Language_Guide.pdf
Re: I simply don't get! #define -
Baltazar - 12.04.2015
Quote:
Originally Posted by Threshold
Код:
doesn't exist and thus can't be undefined.
Those are two different things. They either exist and are defined, or do not exist and are undefined. You can't have both.
|
By saying "can't be undefined" I mean "you can't undefine it".