🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c++
Article #1881

Re: What is sizeof(T&) ??

#1881
From: Steve Clamage
Date: Fri, 01 Sep 1995 04:00
34 lines
1668 bytes
tony@online.tmx.com.au (Tony Cook) writes:

>J. Kanze (kanze@gabi-soft.fr) wrote:

>: 	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.)

>Are you sure about this?  Considering X is a POD, what if the
>programmer has coded:

>	memset(&x, 0, sizeof(X));

>somewhere in their program?  Or does this produce undefined
>behaviour?

I think James meant that only the first 5 bytes of the struct have
meaningful data; the rest is padding needed for alignment. The
compiler must allocate sizeof(X) bytes for any type X, if only
because distinct objects must not overlap.

--
Steve Clamage, stephen.clamage@eng.sun.com

---
[ 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: <MATT.95Aug31210005@physics12.Berkeley.EDU>
Path: arc1-ca.pugleaf.net!128.32.155.1!matt
References: <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!128.32.155.1!matt
From: clamage@Eng.Sun.COM (Steve Clamage)
Newsgroups: comp.std.c++
Subject: Re: What is sizeof(T&) ??
Date: 01 Sep 1995 04:00:05 GMT
Organization: Sun Microsystems Inc., Mountain View, CA
Approved: matt@physics12.Berkeley.EDU (Matt Austern)
Message-ID: <MATT.95Aug31210005@physics12.Berkeley.EDU>
References: <199508290413.VAA02818@corvette.ucr.edu> <41v7eh$2b1@gabi.gabi-soft.fr> <DE7Czw.4ps@online.tmx.com.au>
NNTP-Posting-Host: physics12.berkeley.edu