[PATCH] C undefined behavior fix

Linus Torvalds torvalds@transmeta.com
Fri Jan 4 14:04:00 GMT 2002


In article <20020104121403.D7262F3123@nile.gnat.com> you write:
>
>We can't avoid people writing wrong code, but we can avoid debate as to
>whether the code is right or wrong :-)

However, gcc clearly does the wrong thing with strcpy() right now.

And the gcc people claim it is undefined behaviour, which is not
actually true if you just add two casts (which won't actually change the
low-level RTL at all).  It is implementation-defined, and documented by
gcc to do the bit-wise arithmetic that was exactly what the linker
people expected. 

And we can NOT avoid the debate on whether the code is right or wrong,
when the compiler writers themselves clearly aren't aware of all issues
either. 

The gcc-3 optimization is _bogus_ as per the C standard, and has to be
disabled at least for the case where the pointer was cast to an integer. 

		Linus



More information about the Gcc mailing list