🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: Initializer w/sizeof() on lhs term, okay o

#3455
From: Steve Clamage
Date: Thu, 15 Feb 1996 00:46
32 lines
1940 bytes
In article qcr@venus.roc.csci.csc.com, tottinge@csci.csc.com (Tim
Ottinger) writes:

>In the following example, the problem is manifest nicely, but the actual
>code fragment is clearly nonsensical.  Forgive this.  I didn't want to go
>chasing down the code again.

>It all comes down to a problem where a sizeof() is used on the rhs of an 
>initialization, and it's operating on the object it's initializing:
>
>	someType z  = fred + sizeof(z);
>                ^                  ^^

>Of course, I've changed the inherited code to read:
>
>	someType z  = fred + sizeof(someType);
>                ^                  ^^^^^^^^

The original code is valid as shown. The point of declaration of a name is
immediately after its complete declarator and before its initializer (if any),
with a few exceptions that don't apply to this particular example.

Thus, 'z' has been declared by the time you get to the '=', so you can
use 'sizeof(z)' in its initializer. There is no ambiguity, since the size
of z is the size of 'someType', no matter what the value of the initializer.

---
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.  Moderation policy:
  http://reality.sgi.com/employees/austern_mti/std-c++/policy.html. ]
Technical Details
Message-ID: <4ftia0$c5s@engnews1.Eng.Sun.COM>
Path: arc1-ca.pugleaf.net!in2.uu.net!bounce-back
References: <4fqq6l$qcr@venus.roc.csci.csc.com>

Show Full Headers
Complete Article Headers
From: clamage@Eng.Sun.COM (Steve Clamage)
Message-ID: <4ftia0$c5s@engnews1.Eng.Sun.COM>
X-Original-Date: 14 Feb 1996 20:56:32 GMT
Path: arc1-ca.pugleaf.net!in2.uu.net!bounce-back
Date: 15 Feb 96 00:46:17 GMT
Approved: fjh@cs.mu.oz.au
Newsgroups: comp.std.c++
Subject: Re: Initializer w/sizeof() on lhs term, okay o
Organization: Sun Microsystems Inc.
References: <4fqq6l$qcr@venus.roc.csci.csc.com>
Reply-To: clamage@Eng.Sun.COM
X-Auth: PGPMoose V1.1 PGP comp.std.c++
 iQBFAgUBMSKCd+EDnX0m9pzZAQEybwGAk1lAJimToQfDU4RYVm55DPgsGXZYtFxl
 fSppMWu9fcijxNaK6TF9aTtY2hFSDHjl
 =C9v+