Newsgroups: comp.lang.c Path: utzoo!utgpu!watserv1!watdragon!rose!ccplumb From: ccplumb@rose.uwaterloo.ca (Colin Plumb) Subject: Re: Is #define THING -10 completely safe? Message-ID: <1991Jan27.233142.28302@watdragon.waterloo.edu> Sender: daemon@watdragon.waterloo.edu (Owner of Many System Processes) Organization: University of Waterloo References: <33@christmas.UUCP> Date: Sun, 27 Jan 91 23:31:42 GMT Lines: 39 rtm@island.COM (Richard Minner) wrote: >> #define INT_MIN -2147483648 /* min decimal value of an "int" */ > > Something I've been curious about, should the above be > #define INT_MIN (-2147483648) > > The precedence rules seem to imply that ()'s aren't needed > with a negative integer constant. Could someone confirm or > deny this please? (I always use ()'s out of habit.) Well, unary - has higher precedence than anything except the postfix opertors: [expression] (argument-list) .identifier ->identifier ++ -- Now, none of these are applicable to intergers, so it's safe... except! 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) int i, foo[50]; int *p = &foo[25]; for (i = 0; i < 50; i++) foo[i] = i; printf("%d, %d\n", X1[p], X2[p]); Will print "-35, 15". If onbody's used this particular perversion in the obfuscated C code contest yet, I'm sure they will soon. -- -Colin