Path: utzoo!utgpu!news-server.csri.toronto.edu!rutgers!ucsd!sdd.hp.com!samsung!munnari.oz.au!ditmela!diemen!tasis.eecs.utas.edu.au!charles From: charles@tasis.eecs.utas.edu.au (Charles Lakos) Newsgroups: comp.std.c Subject: Order of allocation of fields in a struct? Message-ID: <1563@diemen.cc.utas.oz> Date: 13 Jun 90 14:00:00 GMT Sender: news@diemen.cc.utas.oz Lines: 29 I wonder if the C standard says anything about the order of allocation of memory to fields of a struct. In particular, suppose that I have typedef struct { int a; char c; real b; } t1; typedef struct { int a; char c; real b; something-else d; } t2; t2 v2, *p ... p = &v2; /* set p to point to v2 of type t2 */ Can I then access the fields of v2 in the following way: (t1 *) p -> b If this is not standardised, is it common practice? (The question interests me from the point of view of implementing object- oriented languages in C. Classes could be implemented as struct's and pointers to the object could be coerced to the relevant type without problem.) ----- Charles Lakos charles@tasis.eecs.utas.edu.au Electrical Engineering & Computer Science University of Tasmania Tasmania, Australia.