프로그램

missing binary operator before token (

(주)CKBcorp., 2022. 2. 10. 15:58
반응형

두줄요약 : #define , #include 쪽 봐라. 그쪽 선언부나 매크로, 선언 순서 쪽 문제 가능성 있다.

 


확인해 볼 건 
1. #ifdef  , #ifndef 값 순서가 맞는지. 종료 쌍 ( #endif ) 가 맞는지.
2. 매크로가 규약에 맞는지. 혹은 특정 플랫폼이나 컴파일러, 아키텍쳐에서만 사용가능한건 아닌지. 
3. 선언값이나 매크로 변경때 인자값이나 괄호 쌓는거나 줄바꿈이 제대로 처리된건지.



https://stackoverflow.com/questions/21338385/what-does-the-compiler-error-missing-binary-operator-before-token-mean



This is not a compiler error, it is a preprocessor error. It occurs when the preprocessor encounters invalid syntax while trying to evaluate an expression in a #if or #elif directive.

One common cause is the sizeof operator in an #if directive:

For example:

  #define NBITS (sizeof(TYPE)*8)
  //later
  #if (NBITS>16)    //ERROR
This is an error because sizeof is evaluated by the compiler, not the preprocesor.

Type casts are also not valid preprocessor syntax:

  #define ALLBITS ((unsigned int) -1)
  //later
  #if (ALLBITS>0xFFFF)    //ERROR
The rules for what can be in a valid expression are here.

Note also that #if will evaluate an undefined macro as 0, unless it looks like it takes arguments, in which case you also get this error:

So if THIS is undefined:

#if THIS == 0  //valid, true

#if THIS > 0 //valid, false

#if THIS() == 0  //invalid. ERROR
Typos in your #if statement can also cause this message.



코드의 문법 에러 = compiler 가 아니고, preprocessor 의 에러라는 것. 전처리 순서를 모르거나 잘못 알고 썼을 때 생기는 에러라는 뜻. 그래서 문법 에러가 아니고, 
preprocessor 가 #define 이나 ... 기타 등등 값을 변경하고 나서 적용하는 매크로나 선언값들이나 if ~ define ~ else ~ endif 등의 관계가 꼬인 것.


 

반응형