c - How is it that "sizeof (char[0])" compiles just fine with GCC -


a colleague of mine inserted (void) sizeof (char[0]) @ end of multi line, macro alternative do {...} while (0) apparently. have looked around can't find reference , surprises me compiles.

is valid c? love reference std.

if compile gcc -pedantic, you'll warning message:

warning: iso c forbids zero-size array [-wpedantic] 

the latest draft of c standard, n1570, section 6.7.6.2 (array declarators) paragraph 1 says:

if expression constant expression, shall have value greater zero.

this part of constraint, char[0] constraint violation, requiring diagnostic conforming c compiler.

(it's not 100% clear that particular clause applies type name char[0] in absence of declared object, general idea standard c not support zero-length arrays.)

gcc supports zero-sized arrays extension, documented here.


Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -