Article View: comp.sys.atari.st
Article #26075Re: Type coercion
From: wheels
Date: Mon, 06 Apr 1987 13:20
Date: Mon, 06 Apr 1987 13:20
26 lines
1612 bytes
1612 bytes
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.
Technical Details
Message-ID:
<245@mks.UUCP>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!water!watnot!watmath!mks!wheelsReferences:
<2499@dalcs.UUCP>Show Full Headers
Complete Article Headers
Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: arc1-ca.pugleaf.net!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?