🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c
Article #253

Re: pointers & order of execution

#253
From: Karl Heuer
Date: Mon, 19 Jun 1989 23:14
18 lines
1477 bytes
In article <921@tukki.jyu.fi> tarvaine@tukki.jyu.fi (Tapani Tarvainen) writes:
>[c marks a place in buffer b, which we want to realloc; old value in t]
>/*2*/	c = b + (c - t);
>Is this guaranteed to work, or is the compiler free to rearrange it as
>	c = (b - t) + c;
>even though b - t is illegal (and fails)?

Yes, this is guaranteed to work; parens must be honored in ANSI C.  Any such
rearrangement is now legal only via the as-if rule, which requires that the
rewrites be transparent to the user.  Thus, this optimization would be legal
for a compiler on a flat architecture (e.g. a pdp11 or vax), but not for a
segmented machine if the value (b-t) is not representable.

Similarly, lacking information about the possible values of j and k, an
integer expression like "i=(i-j)+k" cannot be optimized into "i+=(k-j)" unless
the integer-overflow trap is disabled.  (Which it usually is.)

Karl W. Z. Heuer (ima!haddock!karl or karl@haddock.isc.com), The Walking Lint
Technical Details
Message-ID: <13757@haddock.ima.isc.com>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!cs.utexas.edu!ico!ism780c!haddock!karl
References: <920@tukki.jyu.fi> <921@tukki.jyu.fi>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!cs.utexas.edu!ico!ism780c!haddock!karl
From: karl@haddock.ima.isc.com (Karl Heuer)
Newsgroups: comp.std.c
Subject: Re: pointers & order of execution
Keywords: pointer subtraction, order of execution, realloc
Message-ID: <13757@haddock.ima.isc.com>
Date: 19 Jun 89 23:14:04 GMT
References: <920@tukki.jyu.fi> <921@tukki.jyu.fi>
Reply-To: karl@haddock.ima.isc.com (Karl Heuer)
Organization: Interactive Systems, Boston
Lines: 18