Reputation: 8961
I'm using Visual Studio 2013 and trying to write a preprocessor macro, which will check at compile-time if a VERSION is a valid BCD number:
#define VERSION (uint8)0x01u
#if ((VERSION > 0x99u) || ((VERSION & 0x0Fu) > 0x09u))
#error "Invalid version"
#endif
But for some reason VS2013 shows the following message:
error C1012: unmatched parenthesis : missing ')'
I've checked my parenthesis a few times - but it looks right to me. Is there something I'm missing?
Upvotes: 0
Views: 1592
Reputation:
The preprocessor doesn't understand types, so this cannot work. Assuming uint8
is not a macro, this will expand to
#if (((0)0x01u > 0x99u) || (((0)0x01u & 0x0Fu) > 0x09u))
because all identifiers that are left after macro replacement are replaced by zero. This clearly has syntax errors. The error message you're getting seems misleading to me, but the fact that you're getting an error message at all is appropriate.
Do you really need VERSION
to have type uint8
? If not, you can simply remove the cast.
If you do need to have it as type uint8
, you need to write the expression in such a way that it remains valid even if it gets replaced by 0
, such as ((uint8)+0x01u)
.
Upvotes: 3
Reputation: 1644
you cannot define macros as #define VERSION (uint8)0x01u
define it as'
#define VERSION 0x01u
Upvotes: 1