[cfe-dev] Unused expression and comma operator
Sanghyeon Seo
sanxiyn at gmail.com
Thu Nov 15 03:22:23 PST 2007
This issue is similar to that of conditional operator I raised before.
I concede that "a ? b : c" can be warned as unused expression even if
b or c have side effects, since computation done by ?: itself is
unused.
How about "a, b"?
#define luaZ_initbuffer(L, buff) ((buff)->buffer = NULL, (buff)->buffsize = 0)
luaZ_initbuffer(L, &p.buff);
Comma operators are often used in preprocessor macro. If "a, b" is
changed to "a; b", people who use macro as if it is function in codes
like "if (condition) macro(...)" without braces will get a nasty
surprise.
I think the standard way to replace "a, b" is "do { a; b; }
while(0);". But should this warn?
http://c2.com/cgi/wiki?TrivialDoWhileLoop discusses comma operators,
do while loop, and related tricks in detail.
--
Seo Sanghyeon
More information about the cfe-dev
mailing list