Path: utzoo!utgpu!water!watmath!clyde!rutgers!mit-eddie!uw-beaver!uw-june!pardo From: pardo@june.cs.washington.edu (David Keppel) Newsgroups: comp.lang.c Subject: pcc optimizer strangeness? Keywords: pcc optimize assembly Message-ID: <4061@june.cs.washington.edu> Date: 24 Jan 88 17:01:52 GMT Organization: U of Washington, Computer Science, Seattle Lines: 39 I have a program that compiles some (to me) strange code under pcc even with the (presumed peephole) optimzer turned on (Ultrix). I'm led to wonder if this is even legal C. Basically I'm trying to create an array of range (-1..1) instead of (0..2): main() { static int foo[3]; static int *bar = &foo; bar[-1] = 1; bar[ 0] = 0; bar[ 1] = -1; exit(bar[-1]+bar[1]); /* wierd */ } For the /* wierd */ part, the resulting unoptimized code is: movl L17,r0 movl L17,r1 addl3 4(r1),-4(r0),r0 pushl r0 The resulting optimized code is: movl L17,r0 movl r0,r1 addl3 4(r1),-4(r0),-(sp) And it all works just hunky-dory when I change it to movl L17,r0 addl3 4(r0),-4(r0),-(sp) So my questions are: (a) is this legal C? (b) is this lack of optimization worth telling anybody about? ;-D on (I want a float-indexed array !-) Pardo pardo@cs.washington.edu ucbvax!uw-beaver!uw-june!pardo