I am trying to compare with specific constants in C, and I simplified my program as follows:
#include "stdio.h" #include "stdlib.h" #define INVALID_VALUE -999; int main(void) { int test=0; if(test==INVALID_VALUE) //The error line.. return INVALID_VALUE; return 0; }
And when I use gcc to compile, it throws an error " ". error: expected ‘)’ before ‘;’ token
error: expected ‘)’ before ‘;’ token
Is there a reason this cannot be done?
Remove the semicolon from the INVALID_VALUE definition.
Macros are replaced lexically (symbolically) without understanding the syntax around them. Your macro INVALID_VALUE is set -999;, so your if line extends the macro to:
-999;
if (test==-999;)
which is invalid C syntax
; #define INVALID_VALUE -999;. . .
;
#define INVALID_VALUE -999;
, , expected ‘)’ before ‘;’ token. , ) ;, , , ;. , INVALID_VALUE? #define INVALID_VALUE -999;, ! , , ? , . !
expected ‘)’ before ‘;’ token
)
INVALID_VALUE
, #define , . , . :
#define
, . . ., ., , . , .
, . . .
, .
, , . , .
; .
. C , C.
16- 1970 , C , . , , , .
, C , . C, .
32- , , , , , , .
Half Column at the End
Classical.
You do not need a semicolon after defining something. #define is actually a macro, and it will do an inline extension when compiling.
In this way,
#define IDENTIFIER 10; int j = IDENTIFIER;
will expand as:
int j = 10;;
Change macro
from
to
#define INVALID_VALUE -999
Bye
Source: https://habr.com/ru/post/1782204/More articles:How to get image from this BBC channel using Python and Universal Parser - pythonJava string: replace the string containing the $ sign - javaRedirecting when catching an exception in a method in a model - ruby-on-railsConnect to mysql - pythonHow to deactivate a specific version of a gem? - ruby-on-railsThe difference between the "and" characters in jQuery - javascriptjQuery find () works in IE, but not in Chrome or Firefox - javascriptHow to track product price reductions in a user wishlist? - ruby-on-railsiPhone - MPMoviePlayerController: Code Example Demonstrating Two Problems - iphonehttps://translate.googleusercontent.com/translate_c?depth=1&pto=aue&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1782209/maven-repository-no-longer-exists-now-what&usg=ALkJrhhq_dEsSuFKnrKYkISc7oFf4ePU0wAll Articles