Xref: utzoo comp.arch:14173 comp.lang.c:26224 Path: utzoo!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!wuarchive!decwrl!megatest!djones From: djones@megatest.UUCP (Dave Jones) Newsgroups: comp.arch,comp.lang.c Subject: Re: RISC Machine Data Structure Word Alignment Problems? Message-ID: <12118@goofy.megatest.UUCP> Date: 23 Feb 90 02:01:58 GMT References: <645@mwtech.UUCP) Organization: Megatest Corporation, San Jose, Ca Lines: 28 From article <645@mwtech.UUCP), by martin@mwtech.UUCP (Martin Weitzel): ) There were some recent postings, that pointed out/complained about ) 'holes' in C-struct definitions. ... ) ) My advice in this situation is, to change this code as follows: ) ) char buffer[ ) 2 /* length of message */ ) + 1 /* several flag bits ) + 1 /* type of message */ ) + 4 /* checksum */ ) + 100 /* arbitrary message */ ) ]; ) ) #define m_length(b) (*((short *) (char *)(b) + 0)) ) #define m_flags(b) (*((unsigned char *)(char *)(b) + 2)) ) #define m_type(b) (*((char *) (char *)(b) + 3)) ) #define m_checksum(b) (*((unsigned long *)(char *)(b) + 4)) ) #define m_bytes(b) ( (char *)(b) + 8 ) ) There's probably going to be a flurry of replies telling you why this will not work in the general case. These casts from char* to this-or-that* are not going to work unless the data just happen to be properly aligned for whatever processor you happen to be using.