3 ms·
> The length of the working array depends on the value of i. Not classic C90; only the brain damaged C99 dialect. Prior to C99, sizeof expr is a constant expr
by kazinator 10y ago
> The length of the working array depends on the value of i.
Not classic C90; only the brain damaged C99 dialect.
Prior to C99, sizeof expr is a constant expression, always.
You can easily program in C90. Plenty of currently maintained or even new projects are C90 only.
If using gcc, use gcc -ansi or equivalently -std=c90, and there you are.
There is a way to detect (albeit at run time) when a macro is given an expression which contains side effects. This:
http://git.savannah.nongnu.org/cgit/kazlib.git/tree/sfx.h http://git.savannah.nongnu.org/cgit/kazlib.git/tree/sfx.h
compile the sfx.c into your code, along with the except.c and hash.c modules. Then you can use the SFX_CHECK macro in your macro bodies. For instance, the dict.h header file uses it like this:
#ifdef KAZLIB_SIDEEFFECT_DEBUG
#define dict_isfull(D) (SFX_CHECK(D)->dict_nodecount == (D)->dict_maxcount)
#else
#define dict_isfull(D) ((D)->dict_nodecount == (D)->dict_maxcount)
#endif
If the debugging is enabled, and some place in the application calls dict_isfull(d++), then there will be a diagnostic, thanks to code generated by SFX_CHECK(D), which parses the expression (or pulls the parse out of a cache) and then diagnoses based on the results. Unfortunately, this is a run-time check: the expression has to be stepped on.
(A bit of work could turn this into a static system. E.g the macros could spit out a special annotation, then the output of gcc -E could be collected and post-processed to look for the annotated material and determine if there are side effects.)
I wrote this in around 1999 and it hasn't been maintained since.
The parser has to work with incomplete information and hence deal with ambiguities. For instance (a)(b) could be a function call or a cast of (b) to the type (a). We don't know and so we have to conclude that this is a "maybe side effect" (function call). In the face of ambiguities, we parse the expression multiple ways. If it parses correctly in two ways, we conclude pessimistically: if one of the ways of parsing it suggests there is a side effect we go with that. If errors are encountered in some of the parses, backtracking takes place, and this is done with the help of exception handling, which is built on setjmp/longjmp.