WebKit has a lot of pre-processor lines like this:
#if MACRO1(MACRO2)
For example:
#if PLATFORM(MAC) || (PLATFORM(QT) && USE(QTKIT))
#include "MediaPlayerPrivateQTKit.h"
#if USE(AVFOUNDATION)
#include "MediaPlayerPrivateAVFoundationObjC.h"
#endif
...
So my first thought was that they were function-like macros, but I can’t see how that would work, and I couldn’t find any #defines for these macros anywhere in the source code.
I asked another engineer what it was and he’s never seen multiple macros used like that inside a #if before either.
I found this wiki page that talks about them but it still wasn’t clear to me where they come from,
So my question then: Is this valid C++ or is it being replaced in the code by another tool/language like CMake or something else, and if it is valid C++ is there a spec anyone is aware of that talks about this?
I’m a support engineer for a C++ Static Analysis tool that isn’t handling this syntax. A customer asked us to handle it, but if I’m going to take this to the senior engineer I’d like to not sound like an idiot 🙂 So I’d like the nitty gritty if anyone knows it.
As mentioned in the wiki, in root/trunk/Source/JavaScriptCore/wtf/Platform.h we get a definition for each of these defines. For instance, the
PLATFORMmacro is defined as:The value of
WTF_FEATUREwill be replaced by the platform name to create some macro namedWTF_PLATFORM_WTF_FEATRE. For instance, withWTF_FEATUREpassed into the macro asMAC, you would end up with a expansion ofWTF_PLATFORM_MAC. The pre-processordefineddirective combined with the logicalANDis basically asking whether that macro value defined, and if it is defined, if its value is a “true” value. You would use this macro somewhere else in the pre-processor like:You wouldn’t use it within C++ code itself like
that would cause a bunch of errors from the compiler since
definedis not a C++ keyword, and the evaluation and replacement of the macro within C++ code would end up dumping thedefinedpre-processor directive into any C++ code that directly called the macro. That’s not valid C++.Thanks you to Johannes for pointing out some of these issues.