🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c
Article #1723

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

#1723
From: Dave Hanson
Date: Sat, 15 Sep 1990 18:19
17 lines
1414 bytes
In article <11907@crdgw1.crd.ge.com> volpe@underdog.crd.ge.com (Christopher R Volpe) writes:
    In article <2699@rossignol.Princeton.EDU    , drh@cs.Princeton.EDU (Dave
    Hanson) writes:
    	    static int *s = x + (x-x); /* Does this ``evaluate to'' x+0? */
    	    
    	    even though (x-x) is 0, compilers may not be obliged
    	    to recognize it as 0 because x-x doesn't conform to the allowable
    	    expressions you listed above.
    
    Yes, they are obliged to recognize it as zero because the two 
    operands (which happen to be identical) are both pointers into
    the same array. See K&R II A7.7

x-x indeed evaluates to 0 during execution, but compilers are not
obliged to recognize it as a constant expression that evaluates to 0
during compilation. x-x is not an integral constant expression because
its operands are address constants, not integer constants (see sec. 3.4).
Technical Details
Message-ID: <2752@rossignol.Princeton.EDU>
Path: arc1-ca.pugleaf.net!utzoo!attcan!uunet!cs.utexas.edu!usc!rutgers!njin!princeton!cs!cs.Princeton.EDU!drh
References: <1990Sep14.015241.2152@twinsun.com> <2699@rossignol.Princeton.EDU> <11907@crdgw1.crd.ge.com>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!attcan!uunet!cs.utexas.edu!usc!rutgers!njin!princeton!cs!cs.Princeton.EDU!drh
From: drh@cs.Princeton.EDU (Dave Hanson)
Newsgroups: comp.std.c
Subject: Re: static int x[2], *p = x+(x-x);  ?
Message-ID: <2752@rossignol.Princeton.EDU>
Date: 15 Sep 90 18:19:42 GMT
References: <1990Sep14.015241.2152@twinsun.com> <2699@rossignol.Princeton.EDU> <11907@crdgw1.crd.ge.com>
Sender: news@cs.Princeton.EDU
Organization: Dept. of Computer Science, Princeton University
Lines: 17