Path: utzoo!attcan!uunet!samsung!zaphod.mps.ohio-state.edu!ncar!noao!arizona!dave From: dave@cs.arizona.edu (Dave P. Schaumann) Newsgroups: comp.lang.c Subject: Re: Is #define THING -10 completely safe? Message-ID: <745@caslon.cs.arizona.edu> Date: 28 Jan 91 13:50:21 GMT References: <33@christmas.UUCP> <1991Jan27.233142.28302@watdragon.waterloo.edu> <14999@smoke.brl.mil> Organization: U of Arizona CS Dept, Tucson Lines: 37 In article <14999@smoke.brl.mil> gwyn@smoke.brl.mil (Doug Gwyn) writes: |In article <1991Jan27.233142.28302@watdragon.waterloo.edu> ccplumb@rose.uwaterloo.ca (Colin Plumb) writes: |-As all loyal followers of the Obfuscated C code contest know, |-array[i] == *(array+i) == *(i+array) == i[array]. So |-#define X1 -10 |-#define X2 (-10) |-[...] |-printf("%d, %d\n", X1[p], X2[p]); |-Will print "-35, 15". | |No, that's a ludicrous misinterpretation of the situation. The |compiler does NOT perform a textual "rewrite" of the [] expression |then reparse it. This works as Colin says on my machine (compiling with gcc). Here is the full program: #include #define X1 -10 #define X2 (-10) main(void) { int i, a[50], *p = &a[25] ; for( i = 0 ; i < 50 ; i++ ) a[i] = i ; printf( "X1:%d X2:%d", X1[p], X2[p] ) ; } If Colin's interpretation is wrong, what *is* happening? Dave Schaumann | And then -- what then? Then, future... dave@cs.arizona.edu | -Weather Report