summaryrefslogtreecommitdiffstats
path: root/pb.h
diff options
context:
space:
mode:
authorSteffen Siering <steffen siering gmail com>2012-11-11 22:48:21 +0000
committerPetteri Aimonen <jpa@git.mail.kapsi.fi>2012-11-16 09:24:39 +0200
commitcc29958d34e43ed889536ad4a723fce819544785 (patch)
tree73517c9d9d1679560207702ebd7ff831f707c471 /pb.h
parent0abb764b1816e6a986c10c30444530e11d112cb1 (diff)
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.
Diffstat (limited to 'pb.h')
-rw-r--r--pb.h4
1 files changed, 3 insertions, 1 deletions
diff --git a/pb.h b/pb.h
index dafdfd51..22b10d89 100644
--- a/pb.h
+++ b/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