Article View: comp.std.c
Article #1436struct pointer restrictions. (Was: Order of allocation of fields in a struct?)
From: Chuck.Phillips
Date: Fri, 15 Jun 1990 06:38
Date: Fri, 15 Jun 1990 06:38
46 lines
2345 bytes
2345 bytes
>>>>> On 14 Jun 90 19:02:05 GMT, gwyn@smoke.BRL.MIL (Doug Gwyn) said:
Doug> You can count on a pointer to the first member of a struct being
Doug> convertible to a pointer to the struct and vice-versa, ...
By explicit casting, I certainly _hope_ so! :-)
Doug> ...and from
Doug> various constraints in the standard it is possible to conclude
Doug> that "all structure pointers smell the same", meaning that they
Doug> have the same size and alignment requirements, so it is also
Doug> possible to interconvert pointers to two different structure
Doug> types.
I want to make sure I'm clear on this. Of course, everything malloc()ed
will have the same alignment restrictions because malloc() determines the
restrictions. But what about automatic and static structs? For example, a
struct composed entirely of char's is often less alignment limited _by the
hardware_ than a struct beginning with a double. For example:
struct AllChars {
char First;
char Second[42];
};
int DoSomething ()
{
char OneChar;
struct AllChars WhatAboutMe;
...
}
Are you saying (and is the standard saying) "WhatAboutMe" is _guaranteed_
to have the most restrictive alignment requirements? Are you also saying
that on machines where char's have a unique representation (i.e. different
number of bits or different interpretation of bits) that "&WhatAboutMe"
_must_ be the same kind of pointer as is used for a struct with a double as
its first element? I'd expect both the alignment and the pointer
representation to be implementation defined, unless it is explicitly
mandated in the standard.
Thanks in advance,
--
Chuck Phillips MS440
NCR Microelectronics Chuck.Phillips%FtCollins.NCR.com
Ft. Collins, CO. 80525 uunet!ncrlnk!ncr-mpd!bach!chuckp
Technical Details
Message-ID:
<CHUCK.PHILLIPS.90Jun15073836@haydn.FtCollins.NCR.COM>Path:
arc1-ca.pugleaf.net!utzoo!attcan!uunet!ncrlnk!ncr-mpd!Chuck.PhillipsReferences:
<1563@diemen.cc.utas.oz> <13115@smoke.BRL.MIL>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!attcan!uunet!ncrlnk!ncr-mpd!Chuck.Phillips From: Chuck.Phillips@FtCollins.NCR.COM (Chuck.Phillips) Newsgroups: comp.std.c Subject: struct pointer restrictions. (Was: Order of allocation of fields in a struct?) Message-ID: <CHUCK.PHILLIPS.90Jun15073836@haydn.FtCollins.NCR.COM> Date: 15 Jun 90 06:38:36 GMT References: <1563@diemen.cc.utas.oz> <13115@smoke.BRL.MIL> Sender: uucp@ncr-mpd.FtCollins Organization: NCR Microelectronics, Ft. Collins, CO Lines: 46 In-reply-to: gwyn@smoke.BRL.MIL's message of 14 Jun 90 19:02:05 GMT