0

Working on preprocessor errors and warnings I discovered the following:

When using

#define TEST 4
#ifdef TEST
    #error "Wrong Test"
#endif

It will show the error during compilation, however using

#define TEST 4
#if (TEST==3)
    #error "Wrong Test"
#endif    

Will still show the error, which is not expected. Changing #error directive with #warning it all works as expected.

Can somebody explain how to work around this problem since, in our compilation process we halt on errors and not on warnings.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
EmbedWise
  • 184
  • 1
  • 12
  • 1
    possible duplicate of [Is there a way to both check a macro is defined and it equals a certain value at the same time](http://stackoverflow.com/questions/17160755/is-there-a-way-to-both-check-a-macro-is-defined-and-it-equals-a-certain-value-at) – Chan Kha Vu Apr 22 '15 at 08:47
  • 3
    What compiler are you using? This works correctly for me with gcc. – Paul Hankin Apr 22 '15 at 08:49
  • Anonymous my compiler is arm gcc 4.8.1. However I abstracted the test case and indeed this case is working but in my original file it does not seem to work. I will come back to this – EmbedWise Apr 22 '15 at 09:07
  • Now I isolated the example everything works fine. Building it back in exposed the error. We use -D arguments for gcc to define the variable e.g. TEST. And in a other file this same variable is set when it is undefined. During the preprocessor phases the value changes from the value when undefined to -D define. It also looks like that #error and #warning directives run in different phases of the preprocessing. Summarized the problem is solved, thanks for the comments! – EmbedWise Apr 22 '15 at 10:58

1 Answers1

0

The OP wrote:

Now I isolated the example everything works fine. Building it back in exposed the error. We use -D arguments for gcc to define the variable e.g. TEST. And in a other file this same variable is set when it is undefined. During the preprocessor phases the value changes from the value when undefined to -D define. It also looks like that #error and #warning directives run in different phases of the preprocessing. Summarized the problem is solved, thanks for the comments!

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129