Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2 9/18/84; site rlgvax.UUCP Path: utzoo!linus!philabs!cmcl2!seismo!rlgvax!guy From: guy@rlgvax.UUCP (Guy Harris) Newsgroups: net.lang.c Subject: Re: offsets in structures. Message-ID: <185@rlgvax.UUCP> Date: Thu, 11-Oct-84 18:15:54 EDT Article-I.D.: rlgvax.185 Posted: Thu Oct 11 18:15:54 1984 Date-Received: Sat, 13-Oct-84 01:42:43 EDT References: <393@orion.UUCP> <6080@mcvax.UUCP> Organization: CCI Office Systems Group, Reston, VA Lines: 15 > Watch out! I did a similar thing to calculate the width of a structure: > > (int) ((struct foo *)0 + 1) > > This would give me the sizeof a struct foo, ROUNDED UP to the necessary > alignment. It worked fine, until one day, I ported my program to an > IBM PC with a Lattice C compiler. There it would always evaluate to 1 > (apparently the compiler cancelled the two casts against each other). That's a broken compiler. "(struct foo *)0" is of type "pointer to 'struct foo'", so adding 1 to it should make it point to the "next" object of type "struct foo". Guy Harris {seismo,ihnp4,allegra}!rlgvax!guy