Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sdd.hp.com!usc!dianne.usc.edu!blarson From: blarson@dianne.usc.edu (bob larson) Newsgroups: comp.std.c Subject: Re: Structure Member Padding Message-ID: <25874@usc.edu> Date: 14 Jul 90 06:15:59 GMT References: <13321@smoke.BRL.MIL> <10420@ogicse.ogc.edu> <1990Jul13.104407.29078@jarvis.csri.toronto.edu> Sender: news@usc.edu Distribution: na Organization: USC AIS, Los Angeles Lines: 26 In article <1990Jul13.104407.29078@jarvis.csri.toronto.edu> flaps@dgp.toronto.edu (Alan J Rosenthal) writes: >For: > struct { int i; char c; } var; >and > struct { int i; char c[1]; } var; >to have different layouts, indeed different semantics with respect to layout, >would be quite bizarre. Prime's C compiler stores char variables in the right half of a 2-byte "halfword", and character arrays are packed and start at the left. This does break code that makes assumptions about unions or that no padding is between individually declared chars in a structure. As far as I know, they havn't changed this behavor in their beta-test ansi compiler. union { struct { char a, b, c, d;} x; char y[4]; } Code that assumes that x.a is the same as y[0] and x.d is y[3] will not work on prime's c compiler. note that &a+1 != &b Bob Larson (blars) blarson@usc.edu usc!blarson Hiding differences does not make them go away. Accepting differences makes them unimportant. To join Prime computer mailing list: info-prime-request@ais1.usc.edu