69
69
if the entity names are not disambiguated. A workaround is to
70
70
attach the current line number to the entity name:
72
#define GL_CONCAT0(x, y) x##y
73
#define GL_CONCAT(x, y) GL_CONCAT0 (x, y)
74
extern struct {...} * GL_CONCAT(dummy,__LINE__);
72
#define _GL_CONCAT0(x, y) x##y
73
#define _GL_CONCAT(x, y) _GL_CONCAT0 (x, y)
74
extern struct {...} * _GL_CONCAT (dummy, __LINE__);
76
76
But this has the problem that two invocations of verify from
77
77
within the same macro would collide, since the __LINE__ value
78
would be the same for both invocations.
78
would be the same for both invocations. (The GCC __COUNTER__
79
macro solves this problem, but is not portable.)
80
81
A solution is to use the sizeof operator. It yields a number,
81
82
getting rid of the identity of the type. Declarations like
104
105
extern int (*dummy (void)) [sizeof (struct {...})];
107
* GCC warns about duplicate declarations of the dummy function if
108
-Wredundant_decls is used. GCC 4.3 and later have a builtin
109
__COUNTER__ macro that can let us generate unique identifiers for
110
each dummy function, to suppress this warning.
106
112
* This implementation exploits the fact that GCC does not warn about
107
113
the last declaration mentioned above. If a future version of GCC
108
114
introduces a warning for this, the problem could be worked around
109
by using code specialized to GCC, e.g.,:
115
by using code specialized to GCC, just as __COUNTER__ is already
116
being used if available.
111
118
#if 4 <= __GNUC__
113
extern int (* verify_function__ (void)) \
114
[__builtin_constant_p (R) && (R) ? 1 : -1]
119
# define verify(R) [another version to keep GCC happy]
117
122
* In C++, any struct definition inside sizeof is invalid.
118
123
Use a template type to work around the problem. */
125
/* Concatenate two preprocessor tokens. */
126
# define _GL_CONCAT(x, y) _GL_CONCAT0 (x, y)
127
# define _GL_CONCAT0(x, y) x##y
129
/* _GL_COUNTER is an integer, preferably one that changes each time we
130
use it. Use __COUNTER__ if it works, falling back on __LINE__
131
otherwise. __LINE__ isn't perfect, but it's better than a
133
# if defined __COUNTER__ && __COUNTER__ != __COUNTER__
134
# define _GL_COUNTER __COUNTER__
136
# define _GL_COUNTER __LINE__
139
/* Generate a symbol with the given prefix, making it unique if
141
# define _GL_GENSYM(prefix) _GL_CONCAT (prefix, _GL_COUNTER)
121
143
/* Verify requirement R at compile-time, as an integer constant expression.