OMGtechy OMGtechy - 21 days ago 4x
C Question

What is this syntax inside a GNU C statement expression extension?

I came across this syntax today and couldn't work out what it meant:

// Uses the GNU C statement expression extension
#define envSet(name) ({ \
static int initialised; \
static bool set; \
(void) "" name; \
if (!initialised || !g_cacheEnv) { \
const char *value = getenv(name); \
set = value != NULL; \
initialised = true; \
} \
set; \

The specific line I cannot understand is:

(void) "" name; \

Could somebody please shed some light on this?


It looks like a way to statically ensure that name is a string literal and not some other type.

If you do (void)"" "hello"; then it is a valid C expression.

But if you do something like (void)"" 1; then you get a syntax error.