C question: typecast changes behavior with optimizations enabled.

Ian Lance Taylor iant@google.com
Tue Sep 26 18:02:00 GMT 2006


Adam Dickmeiss <adam@indexdata.dk> writes:

> Consider the attached which sweeps through an array of chars..
> 
> 1) If a typecast is used (CAST defined), the *src is not updated and
> main will see (sz == 0).
> 
> 2) If no typecast is used, *src is updated, and size == 1.

1) Wrong mailing list.  This would be appropriate for gcc-help or for
   a list for general C language questions.

2) Looks like an aliasing problem.  Try compiling with
   -fno-strict-aliasing.  Look at the documentation for
   -fstrict-aliasing and -Wstrict-aliasing.

Ian



More information about the Gcc mailing list