🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.gcc.bug
Article #1877

Re: constant expression folding problem?

#1877
From: Phil Dykstra
Date: Sat, 08 Oct 1988 01:26
20 lines
1245 bytes
> The compiler may still barf, since you are trying to dereference a
> NULL pointer (guarnteed to be a problem), ....

A couple of other people fell in a similar pit.  The code (expanded):

	char *foo = (char *)(((struct test *)0)->s);

does *not* dereference any pointers.  `s' is an array so it could
have been written &((struct test *)0)->s[0]), but that is unnecessary,
the (char *) is simply a cast, and perhaps the most subtle:
"((struct test *)0)->" does not dereference through zero, rather
is says that 0 is the *value* (i.e. contents) of the struct pointer.
What the expression really means is "give me the address of the s
array within a structure located at address zero", i.e. what is the
byte offset of s within the structure.  It really is static.

I wasn't kidding what I listed all of the C compilers that can handle
this correctly.

- Phil
Technical Details
Message-ID: <8810072126.aa03050@SPARK.BRL.MIL>
Path: arc1-ca.pugleaf.net!utzoo!telly!ddsw1!mcdchg!rutgers!tut.cis.ohio-state.edu!BRL.MIL!phil

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!telly!ddsw1!mcdchg!rutgers!tut.cis.ohio-state.edu!BRL.MIL!phil
From: phil@BRL.MIL (Phil Dykstra)
Newsgroups: gnu.gcc.bug
Subject: Re:  constant expression folding problem?
Message-ID: <8810072126.aa03050@SPARK.BRL.MIL>
Date: 8 Oct 88 01:26:33 GMT
Sender: daemon@tut.cis.ohio-state.edu
Distribution: gnu
Organization: GNUs Not Usenet
Lines: 20