Messages in this thread | | | From | Michal Jaegermann <> | Subject | Re: egcs-1.1.2 ping bug also causes miscompilation of pcbit isdn driver | Date | Sun, 13 Jun 1999 16:04:29 -0600 (MDT) |
| |
Lars Heete wrote:
> --------------------- test case ---------------------- > #include <stdio.h> > int main(int argc, char **argv) { > struct {char c1, c2, c2, 4;} t; > t.c4 = 0x78; t.c3 = 0x56; t.c2 = 0x34; t.c1 = 0x12; > printf("0x%x\n", *((unsigned long*) &t)); > return 0; > } > > gives 0x12 with egcs-1.1.2 on i386, instead of 0x78563412.
From the fact that you can write a code like that does not follow that you should. Such C should be classified as a bug on its own (and I am not talking about trivially missing 'c' before '4' in 't' declaration). The first question is how do you know that sizeof(t) is the same as sizeof(unsigned long) and that they have the same layout in memory? The answer is "you don't" on both counts and if you think that you do you are deeply mistaken.
Even if you guessed right on some particular platform then coding like that you have a pretty good chance that you will cause an unaligned access. i386 is much less sensitive than Alpha to that but will take a performance hit in any case. On Alpha you will also find nastygrams in you Linux log files but this is the way how Linux kernels are coded.
It looks like that egcs-1.1.2 should get extra brownie points for exposing shoddy programming practices. :-)
Michal
- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.rutgers.edu Please read the FAQ at http://www.tux.org/lkml/
| |