Article View: comp.std.c++
Article #1889Re: What is sizeof(T&) ??
From: David Sachs
Date: Fri, 01 Sep 1995 17:24
Date: Fri, 01 Sep 1995 17:24
30 lines
1962 bytes
1962 bytes
>J. Kanze (kanze@gabi-soft.fr) wrote:
> (Concerning the last, consider the following:
> struct X { int i ; char c ; } ;
> X x ;
> char c[ 3 ] ;
> On my system, sizeof( X ) == 8, as does sizeof( x ). And of course,
> sizeof( c ) == 3. Curiously, however, the two variables only take up a
> total of 8 bytes; in this particular case, the physical sizeof x is 5,
> and not 8. This is a perfectly legal, and frequent, implementation.)
This is perfectly legal, and will vary from system to system
Presumably this was run on a system, where intergers require alignment
at a multiple of 4 bytes. In this case, struct X must be padded out to
a multiple of 4 bytes, in this case 8 bytes. The 3 unused bytes in an
object of type X, exist, but their contents are meaningless.
The padding ensures that the integer subobject i, will be properly
aligned if you define an array of X.
--
** The Klingons' favorite food was named by the first earthling to see it **
David Sachs - Fermilab, HPPC MS369 - P. O. Box 500 - Batavia, IL 60510
Voice: 1 708 840 3942 Deparment Fax: 1 708 840 3785
[ comp.std.c++ is moderated. Submission address: std-c++@ncar.ucar.edu.
Contact address: std-c++-request@ncar.ucar.edu. The moderation policy
is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]
Technical Details
Message-ID:
<427f27$o5a@fsgm01.fnal.gov>Path:
arc1-ca.pugleaf.net!engnews2.Eng.Sun.COM!taumet!clamageReferences:
<199508290413.VAA02818@corvette.ucr.edu> <41v7eh$2b1@gabi.gabi-soft.fr> <DE7Czw.4ps@online.tmx.com.au>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!engnews2.Eng.Sun.COM!taumet!clamage From: b91926@fsgm01.fnal.gov (David Sachs) Newsgroups: comp.std.c++ Subject: Re: What is sizeof(T&) ?? Date: 1 Sep 1995 17:24:20 GMT Organization: FERMILAB, Batavia, IL Approved: clamage@eng.sun.com (comp.std.c++) Message-ID: <427f27$o5a@fsgm01.fnal.gov> References: <199508290413.VAA02818@corvette.ucr.edu> <41v7eh$2b1@gabi.gabi-soft.fr> <DE7Czw.4ps@online.tmx.com.au> Reply-To: sachs@fnal.fnal.gov NNTP-Posting-Host: taumet.eng.sun.com Content-Type: text X-Newsreader: NN version 6.5.0 #4 (NOV) Content-Length: 1097 X-Lines: 26 Originator: clamage@taumet