Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| From | John May <nospam@nospam.com> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Dereferencing type-punned pointer |
| Date | 2012-07-18 20:41 +0000 |
| Organization | Aioe.org NNTP Server |
| Message-ID | <ju7722$ttq$2@speranza.aioe.org> (permalink) |
I keep getting this warning in GCC with the code segment below. file.c:256 "warning: dereferencing type-punned pointer will break strict-aliasing rules" /*****************************************/ char buffer[SIZE]; int length, type; /* Code to fill buffer */ length = ntohs( *((unsigned short *)buffer) ); type = ntohs( *((unsigned short *)buffer + 1) ); /*****************************************/ I'm trying to take the first two bytes (in network byte order) off the buffer and put them in the length, followed by the next two bytes into the type. GCC complains about the length conversion, but not the type. What does this warning mean, and should I bother with it? I don't want to keep checking this forum, so answers by email required. Quick responses appreciated. John
Back to comp.lang.c | Previous | Next — Next in thread | Find similar | Unroll thread
Dereferencing type-punned pointer John May <nospam@nospam.com> - 2012-07-18 20:41 +0000
Re: Dereferencing type-punned pointer Keith Thompson <kst-u@mib.org> - 2012-07-18 14:14 -0700
Re: Dereferencing type-punned pointer Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-07-19 01:33 +0100
Re: Dereferencing type-punned pointer Keith Thompson <kst-u@mib.org> - 2012-07-18 14:17 -0700
Re: Dereferencing type-punned pointer Ike Naar <ike@sverige.freeshell.org> - 2012-07-19 06:16 +0000
Re: Dereferencing type-punned pointer Keith Thompson <kst-u@mib.org> - 2012-07-19 01:35 -0700
Re: Dereferencing type-punned pointer Ike Naar <ike@sdf.lonestar.org> - 2012-07-19 14:11 +0000
Re: Dereferencing type-punned pointer Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-07-19 01:56 +0100
Re: Dereferencing type-punned pointer Nobody <nobody@nowhere.com> - 2012-07-20 07:40 +0100
csiph-web