Strange error in C compiler
2007-12-25 7:53:00
1) There is the only (almost?) portable way to test the
value of address constants - to use additional variable:
extern _DYNAMIC[];
/* global - to avoid optimizations, though gcc I use doesn't
* optimize "if" when pDYNAMIC is local
*/
int * pDYNAMIC = _DYNAMIC;
...
{
if (pDYNAMIC) ....
else ....
}
I must note the error in some answers. Their authors
propose to test *_DYNAMIC. Obviously, this may cause NULL
pointer access and therefore coredump.
2) The source of strange behavior of the C compiler is
its origin. GCC tries to optimize the "if" always,
MS-DOS' Microsoft and Borland C don't make any presumptions about
the value of address constants, and only PCC-derived
compilers (3 of them have been tested, including SunOS')
behave strangely.
Thanks,
--
Leonid A. Broukhis
Comments
Got something to say?
You must be logged in to post a comment.

