Path: utzoo!attcan!uunet!timbuk!cs.umn.edu!uc!tut.cis.ohio-state.edu!cs.utexas.edu!uwm.edu!rpi!batcomputer!munnari.oz.au!goanna!ok From: ok@goanna.cs.rmit.oz.au (Richard A. O'Keefe) Newsgroups: comp.lang.c Subject: Re: For vs while (was Re: Comparing strings...) Message-ID: <4044@goanna.cs.rmit.oz.au> Date: 22 Oct 90 11:25:56 GMT References: <2205.271700c2@cc.nu.oz.au> <1990Oct13.190106.15615@ux1.cso.uiuc.edu> <8308@scolex.sco.COM> Organization: Comp Sci, RMIT, Melbourne, Australia Lines: 34 In article <8308@scolex.sco.COM>, seanf@sco.COM (Sean Fagan) writes: > #define while(cond) for(;cond;) > > (I'm sitting here trying to think of any case where this will break > [no pun intended 8-)] something; I can't think of any, offhand.) Here's one: do i++; while (p(i)); > If you have something such as > while () { > whatever; > } > this will be an infinite loop given the macro, but a syntax error otherwise. In gcc it's a syntax error. In a guide to ANSI C that I have before me, it says that "a macro argument is ONE or more preprocessing tokens. I think this was a nasty thing for the committee to do: it is the one thing which has broken most of my code. Yes, the standard _does_ permit the definition of macros that look like functions with no arguments: #define no_arg_mac() stuff ... no_arg_mac() ... unfortunately old preprocessors that were happy with no tokens in an argument tended to be unhappy with no arguments in a definition. So I have to do #ifdef __STDC__ #define no_arg_mac() stuff #else #define no_arg_mac(DUMMY) stuff #endif Snarl. (Naturally, I figured out how to do that _after_ I'd added dummy arguments to the invocations in the files I really cared about. Sigh.) -- Fear most of all to be in error. -- Kierkegaard, quoting Socrates.