------- Comment #7 from mikulas at artax dot karlin dot mff dot cuni dot cz 2009-07-07 16:31 ------- > > extern int c; > > int a(void) > > { > > return *(short *)(void *)&c; > > } > > This is a very bad example of a false positive as you are acessing an > int as a short; that is undefined. I will look at your code later on, > my laptop for home is currently broken.
Whether it is a false positive or not depends on the context. For example, if I call function a() from function b(): int b(void) { c = 0x12345678; __asm__ volatile ("":::"memory"); return a(); } the code is valid and the function b() must return a fixed value depending on the endianity of the machine. That __asm__ statement works as a barrier that prevents the compiler from reordering two accesses to "c". So I am not against the warning. The warning is good. The problem is that there is no way to shut up the warning. -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40665