🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c
Article #1694

static int x[2], *p = x+(x-x); ?

#1694
From: Paul Eggert
Date: Fri, 14 Sep 1990 01:52
25 lines
1510 bytes
ANSI C 3.4 (page 56 lines 22-27) says:

	More latitude is permitted for constant expressions in initializers.
	Such a constant expression shall evaluate to one of the following:

	o	an arithmetic constant expression,
	o	a null pointer constant,
	o	an address constant, or
	o	an address constant for an object type plus or minus an
		integral constant expression.

What does ``evaluate to'' mean here?  I thought evaluation yields a value
(see 3.1.5), but here it seems to yield an expression.  For example, which
of the following declarations are OK, and why?

    static int x[2];
    static int *p = 1 + x; /* int+addr, not addr+int */+
    static int *q = x + (int)(0.1 + 0.9); /* Does this ``evaluate to'' x+1? */
    static int *r = &x[(int)(0.1 + 0.9)]; /* Is this equivalent to the above? */
    static int *s = x + (x-x); /* Does this ``evaluate to'' x+0? */


A nit: the phrase ``pointer to an lvalue ... or to a function designator''
(lines 32-33) is sloppy, because lvalues and function designators are
_expressions_, while pointers point to _objects_.
Technical Details
Message-ID: <1990Sep14.015241.2152@twinsun.com>
Path: arc1-ca.pugleaf.net!utzoo!attcan!uunet!wuarchive!zaphod.mps.ohio-state.edu!usc!orion.oac.uci.edu!ucivax!ucla-cs!twinsun!eggert

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!attcan!uunet!wuarchive!zaphod.mps.ohio-state.edu!usc!orion.oac.uci.edu!ucivax!ucla-cs!twinsun!eggert
From: eggert@ata.twinsun.com (Paul Eggert)
Newsgroups: comp.std.c
Subject: static int x[2], *p = x+(x-x);  ?
Message-ID: <1990Sep14.015241.2152@twinsun.com>
Date: 14 Sep 90 01:52:41 GMT
Sender: news@twinsun.com
Organization: Twin Sun, Inc
Lines: 25
Originator: eggert@ata
Nntp-Posting-Host: ata