🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: Question about sizeof in C/C++.

#1149
From: Jim Adcock
Date: Thu, 24 Dec 1992 00:15
17 lines
987 bytes
jamesc@swapsdev.state.state.COM.AU (James Cribb) writes:
| Given
| 
|     struct Something*  ps;
|     unsigned  k;
| 
| do the C or C++ standards guarantee that
| 
|     &ps[k] == ((char*) ps) + k * sizeof(struct Something)

No.  The relationship holds only if k is chosen such that k is greater
than or equal to zero [true since k unsigned], and k is less than or equal 
to the number of elements in the array pointed-to by ps, assuming ps 
points at a valid array of type Something, and in C++ assuming that 
that operator& isn't user-defined on struct [class] Something....

Did I miss anything?
Technical Details
Message-ID: <1992Dec24.001540.30000@microsoft.com>
Path: arc1-ca.pugleaf.net!sparky!uunet!microsoft!hexnut!jimad
References: <jamesc.724544278@bart> <wwJXVB3w164w@amfent.Gwinnett.COM>

Show Full Headers
Complete Article Headers
Newsgroups: comp.std.c++,comp.std.c
Path: arc1-ca.pugleaf.net!sparky!uunet!microsoft!hexnut!jimad
From: jimad@microsoft.com (Jim Adcock)
Subject: Re: Question about sizeof in C/C++.
Message-ID: <1992Dec24.001540.30000@microsoft.com>
Date: 24 Dec 92 00:15:40 GMT
Organization: Microsoft Corporation
References: <jamesc.724544278@bart> <wwJXVB3w164w@amfent.Gwinnett.COM>
Lines: 17