Fix STATIC_ASSERT macro when using multiple .proto files.
The __COUNTER__ macro (used for generating unique names) is at least supported by gcc, clang and Visual Studio. With this change test_compiles.c is compilable, since no more typedefs are redefined. Compilers/Preprocessors not supporting __COUNTER__ error's are still possible which are hopfully handled by the usage of __LINE__ in most sittuations. Added unit test for the problem.
This commit is contained in:
committed by
Petteri Aimonen
parent
0abb764b18
commit
cc29958d34
4
pb.h
4
pb.h
@@ -26,7 +26,9 @@
|
||||
|
||||
/* Compile-time assertion, used for checking compatible compilation options. */
|
||||
#ifndef STATIC_ASSERT
|
||||
#define STATIC_ASSERT(COND,MSG) typedef char static_assertion_##MSG[(COND)?1:-1];
|
||||
#define STATIC_ASSERT(COND,MSG) typedef char STATIC_ASSERT_MSG(MSG, __LINE__, __COUNTER__)[(COND)?1:-1];
|
||||
#define STATIC_ASSERT_MSG(MSG, LINE, COUNTER) STATIC_ASSERT_MSG_(MSG, LINE, COUNTER)
|
||||
#define STATIC_ASSERT_MSG_(MSG, LINE, COUNTER) static_assertion_##MSG##LINE##COUNTER
|
||||
#endif
|
||||
|
||||
/* Number of required fields to keep track of
|
||||
|
||||
Reference in New Issue
Block a user