views:

65

answers:

1

How to trigger C-preprocessor error about missing definition at #if? I'm using LLVM/Clang/Xcode.

This code works.

#define AAAAA 1
#if AAAAA
#endif

And I expected this code will be an error for undefined symbol.

//#define AAAAA 1     Removed definition.
#if AAAAA
#endif

But it did not. Is this standard/regular behavior? And is there other way to triggering preprocessor error?

+1  A: 

It sounds like you want to raise an error if a particular symbol is not defined. If so then just use the #error preprocessor directive

#ifndef AAAAA
#error Some Message
#endif
JaredPar
There's a typo in the example code. The correct syntax is `#ifndef AAAAA` or `#if !defined(AAAAA)`
Jim Huang
@Jim, thanks updated
JaredPar
Thanks! This is what I've been looking for!
Eonil