This message is in MIME format. The first part should be readable text, while the remaining parts are likely unreadable without MIME-aware tools. ---1463809521-2015777660-1222882627=:3904 Content-Type: TEXT/PLAIN; charset=UTF-8 Content-Transfer-Encoding: QUOTED-PRINTABLE On Tue, 30 Sep 2008, William "Chops" Westfield wrote: >=20 > On Sep 22, 2008, at 9:41 AM, sergio masci wrote: >=20 > >> I'm dealing with "pointers to 8-Bit byte" a lot. Some times though, = =20 > >> I want to read a 16-Bit value from the network frame, and a handy =20 > >> way to do this is: > >> > >> *(uint16_t const *)p >=20 > Bad programmer. Not portable to systems with different endianness or =20 > alignment restrictions. Things like this should be hidden in a macro: > GETNET16(p) >=20 > Which can have a definition somewhere between *(uint16_t *)(p) and > NTOHS(GETSHORT(p)) >=20 > BillW >=20 Actually I'm not the author of the few lines you cited. I actually=20 responded with the following: On Mon, 22 Sep 2008, sergio masci wrote: > > On Mon, 22 Sep 2008, Tom=C3=A1s =C3=93 h=C3=89ilidhe wrote: > > > Peter Loron wrote: > > > I'm a major fan of type checking. > > > > Here here! > > > > I'm doing low-level network programming in C at the moment, and I'm > > dealing with "pointers to 8-Bit byte" a lot. Some times though, I want > > to read a 16-Bit value from the network frame, and a handy way to do > > this is: > > > > *(uint16_t const *)p > > > > One of the times though, I neglected to put in the second asterisk, so = I > > had: > > > > *(uint16_t const)p > > > > Of course though the compiler puked straight away when I tried to > > compile it: TYPE MISMATCH! If it had silently compiled it then I would > > have had a hard-to-track-down bug. Type mismatch is one of the most > > beautiful errors! > > Actually 'C's casting mechanism is BAD BAD BAD!!!! > > It breaks 'C's type checking in ways many programmers don't even realise. > Again we are forced to rely on programmer disciplin to prevent obscure > bugs from creaping into code. > > Regards > Sergio Masci ---1463809521-2015777660-1222882627=:3904 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline -- http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist ---1463809521-2015777660-1222882627=:3904--