eric@snark.UUCP (Eric S. Raymond) (12/22/88)
> Finally, I question why this business of checking for old-fashioned > assignment operators is still in Unix C compilers. After all, V7 came > out around 10 years ago! Does anyone really have around any code that hasn't > been converted to the new syntax by *now*? Heh-heh-heh. Naive, ain't he? I ran across a related gotcha in some old comp.sources.unix code recently. I got a bunch of "warning: old-style assignment" messages. I sicced my trusty gnumacs on 'em with a C-X C-`, only to find myself looking at several instances of card=NOVALUE; "What", I said, "does it all mean?" Not being entirely thick between the ears, I looked up at the head of the file. I found #define NOVALUE -1 and mentally consigned the hapless geek who'd originated the program to an eternal hell of three-piece-suits and COBOL coding until I looked at the rest of it and realized I was ranking on some student's proud first project. He did OK otherwise; it worked and I still run it occasionally. As it turns out, the least intrusive fix was to change the #define to (-1). But the real moral of this story, gentlebeings, is: Whitespace Is Your Friend. When in doubt, use some! -- Eric S. Raymond (the mad mastermind of TMN-Netnews) Email: eric@snark.uu.net CompuServe: [72037,2306] Post: 22 S. Warren Avenue, Malvern, PA 19355 Phone: (215)-296-5718
guy@auspex.UUCP (Guy Harris) (12/22/88)
>> Does anyone really have around any code that hasn't >> been converted to the new syntax by *now*? > >Heh-heh-heh. Naive, ain't he? ... > card=NOVALUE; ... >#define NOVALUE -1 Actually, the problem isn't that the code in question hasn't been converted to the new syntax; the problem is that the code in question fails if the old syntax is honored. A compiler that accepts *only* the new syntax will do the right thing with that statement, i.e. assign -1 to "card". (Yes, I tried it on such a compiler - it worked.) Nevertheless, White Space is Still Your Friend, since if you put the white space in compilers that still honor the old syntax will do the right thing as well.
john13@garfield.MUN.EDU (John Russell) (12/24/88)
In article <785@auspex.UUCP> guy@auspex.UUCP (Guy Harris) writes: > > card=NOVALUE; > >#define NOVALUE -1 > >Nevertheless, White Space is Still Your Friend, since if you put the >white space in compilers that still honor the old syntax will do the >right thing as well. Negative define values are also a good place to use parentheses. There is more than one way for the compiler to choke on an unparenthesized number. eg. #define NOVALUE (-1) card2 = card1-NOVALUE Either whitespace are brackets will allow it to parse correctly in this case. John -- "If you steal all money, kids not be able to BUY TOYS!" -- Saturday morning cartoon character explaining why theft is bad