Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!utgpu!water!watnot!watmath!mks!wheels From: wheels@mks.UUCP Newsgroups: comp.sys.atari.st Subject: Re: Type coercion Message-ID: <245@mks.UUCP> Date: Mon, 6-Apr-87 08:20:50 EST Article-I.D.: mks.245 Posted: Mon Apr 6 08:20:50 1987 Date-Received: Mon, 6-Apr-87 23:46:37 EST References: <2499@dalcs.UUCP> Organization: Mortice Kern Systems, Waterloo, Ont. Lines: 26 Keywords: C, Modula-2, long, int, conversion Summary: what about alignment? In article <2499@dalcs.UUCP>, silvert@dalcs.UUCP (Bill Silvert) writes: > Type coercion in this case means putting both formulations in the same > location by using a union: > > union { long datetime; > structure { int date; > int time; > } pair > } trick; > > (apologies if I haven't got the syntax quite right) > > I have used this in my own datesetting program and find it convenient, > but wonder if it creates problems with other compliers and languages. > Clearly this usage assumes that structures are stored I haven't used unions much, but isn't it true that C may attempt to re-align the items within a structure (or union) to lie on proper boundaries (e.g. word boundaries, longword boundaries, etc) where necessary? This means that there may be padding bytes within the structure. Could this cause errors where the elements of the structures within the union don't lie "on top of one another" as one would expect? -- Gerry Wheeler {seismo,decvax,ihnp4}!watmath!mks!wheels Mortice Kern Systems Inc.