How to overcome vC ++ C4003 warning when writing generic code for gcc and vC ++

I have code that compiled in both gcc and vC ++. The code has a common macro that is called in two scenarios.

  • When we pass it some parameters.
  • If we do not want to pass him any parameters.

An example of such a code:

#define B(X) A1##X int main() { int B(123), B(); return 0; } 

Expected output at the compilation preprocessing stage:

 int main() { int A1123, A1; return 0; } 

The output for gcc and vC ++ is as expected, but vC ++ gives a warning:

 warning C4003: not enough actual parameters for macro 'B' 

How to remove this warning and get the expected result?

Thanks.

+4
source share
2 answers

This may work depending on the version of VC ++, etc.

 #define B(...) A1##__VA_ARGS__ 

I don’t know if vC ++ will like empty va args, but it should be done - let me know if this works :)

+2
source

For Visual C ++, you need to use the #pragma warning directive . The warning you receive is C4003 (C => Compiler), 4003 => the warning number.

 #pragma warning (disable: 4003) #define B(X) A1##X int main() { int B(123), B(); return 0; } 

Not sure about GCC, but I suspect that you can refuse to define this pragma for GCC and suppress the warning (if there is any other way).

+1
source

Source: https://habr.com/ru/post/1302981/


All Articles