🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c
Article #183

Re: Intermediate addr outside object: legal?

#183
From: Shankar Unni
Date: Mon, 06 Apr 1992 18:43
27 lines
1734 bytes
In comp.std.c, darcy@druid.uucp (D'Arcy J.M. Cain) writes:

> Chapter 3.3.2.1 says that E1[E2] is identical to "(*(E1+(E2)))."  After
> expanding macros the above becomes "(foo - 8000)[9000]" which is
> identical to "(*((foo - 8000)+(9000)))."  Removing superfluous parens
> that gives "*(foo - 8000 + 9000)" or "*(foo + 1000)" which looks
> perfectly legitimate to me.

But you see, the whole point of the question is that the C standard
*cannot* assume that an implementation does constant folding.  We must
look at the expression exactly as if each operation in the expression
were performed separately in some serial order mandated by the standard.

All this discussion just confirms for me that the result of this
expression is "undefined".

This, of course, does not address the question of what is "the right
thing to do" when the compiler sees this expression (the user-
friendliness question).  Is it reasonable for the program to get a
SIGSEGV on this?  I.e. is this some sort of commonly used (albeit
questionable) idiom in some context that I'm not aware of?

Thanks once again,
-----
Shankar Unni                                 Internet: shankar@iag.hp.com
HP International Contract Programming          HPDESK: Shankar UNNI / HP4700
Phone : +1-408-447-4007                          UUCP: ...!hplabs!hpda!shankar
Technical Details
Message-ID: <2160002@aspen.IAG.HP.COM>
Path: arc1-ca.pugleaf.net!sparky!uunet!usc!sdd.hp.com!hpscdc!hplextra!hpcc05!aspen!shankar
References: <2160001@aspen.IAG.HP.COM>

Show Full Headers
Complete Article Headers
From: shankar@aspen.IAG.HP.COM (Shankar Unni)
Date: Mon, 6 Apr 1992 18:43:06 GMT
Subject: Re: Intermediate addr outside object: legal?
Message-ID: <2160002@aspen.IAG.HP.COM>
Organization: HP International Contract Programming
Path: arc1-ca.pugleaf.net!sparky!uunet!usc!sdd.hp.com!hpscdc!hplextra!hpcc05!aspen!shankar
Newsgroups: comp.std.c
References: <2160001@aspen.IAG.HP.COM>
Lines: 27