🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c
Article #5019

Re: offsetof() and `address constant expression': LONG

#5019
From: Norman Diamond
Date: Sat, 13 Apr 1996 01:32
31 lines
2037 bytes
In article <4kk988$rt2@falcon.ccs.uwo.ca>, Dave Kinchlea
<kinch@julian.uwo.ca> writes 100 lines more than this:
>Seems pretty clear that the use below does not fit this description
>[arguments to offsetof] but I would like some confirmation before I
>send this back to the author.  [...]
>ICELLS is a macro (100) and cells is an integer.

Sounds like you already got it:

>On Thu, 11 Apr 1996, Roger Glover wrote:
>>> bp = (Block*) malloc(offsetof(Block, cell[ICELLS + cells]));
>> Plauger and Brodie's "Standard C Quick Reference" [...] says [...]
>>         #define offsetof(s-type,mbr)  <size_t constant expression>
>>     The macro yields the offset in bytes of member mbr from the beginning
>>     of structure type s-type, where for X of type s-type, &X.mbr is an
>>     address constant expression.

Looks like Plauger and Brodie forgot to say *static* X of type s-type.
However, they got the rest of it right.

>> Well let's break that down a bit.  &X.mbr must be constant,

Yes.  And the standard's section on constant expressions, paragraph on
address constants, says:  "[...] but the value of an object shall not be
accessed by one of these operators."  So the + operator which accesses
the value of cells does not yield a constant expression.
--
 <<  If this were the company's opinion, I would not be allowed to post it.  >>
"I paid money for this car, I pay taxes for vehicle registration and a driver's
license, so I can drive in any lane I want, and no innocent victim gets to call
the cops just 'cause the lane's not goin' the same direction as me" - J Spammer
Technical Details
Message-ID: <4kn07u$fqf@usenet.pa.dec.com>
Path: arc1-ca.pugleaf.net!tbj.dec.com!diamond
References: <4kk988$rt2@falcon.ccs.uwo.ca>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!tbj.dec.com!diamond
From: diamond@tbj.dec.com (Norman Diamond)
Newsgroups: comp.std.c
Subject: Re: offsetof() and `address constant expression': LONG
Date: 13 Apr 1996 01:32:46 GMT
Organization: Digital Equipment Corporation Japan , Tokyo
Message-ID: <4kn07u$fqf@usenet.pa.dec.com>
References: <4kk988$rt2@falcon.ccs.uwo.ca>
Reply-To: diamond@tbj.dec.com (Norman Diamond)
NNTP-Posting-Host: jit533.tbj.dec.com