Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2 9/18/84; site fortune.UUCP Path: utzoo!watmath!clyde!burl!ulysses!mhuxj!ihnp4!fortune!olson From: olson@fortune.UUCP (Dave Olson) Newsgroups: net.lang.c Subject: Re: on1 construct Message-ID: <4594@fortune.UUCP> Date: Mon, 5-Nov-84 16:41:17 EST Article-I.D.: fortune.4594 Posted: Mon Nov 5 16:41:17 1984 Date-Received: Tue, 6-Nov-84 05:25:08 EST References: <124@cadvax> Reply-To: olson@fortune.UUCP (Dave Olson) Distribution: net Organization: Fortune Systems, Redwood City, CA Lines: 38 In article <124@cadvax> jacob@cadvax.UUCP (Jacobo Bulaevsky) writes: >What I've come up with looks like: > >#define on1(X) static char first_time_in = TRUE; if (first_time_in) {first_time_in = FALSE; X;} > >But unfortunately this macro has to be used like: > > on1 ( > bla, bla, bla... > ); > >which is VERY inappropriate. Can anybody out there think of a better >macro definition, comments, suggestions? The macro you propose won't even work with most versions of cpp. I presume you meant that it must be used as: on1 ( bla; bla; bla... ); (Note the ';' instead of ','. Most versions of cpp will NOT allow macro functions with variable #'s of arguments.) If your version of cpp accepts multi-line macros and invocations (as most, and apparently yours, do), you can simply use: on1( bla1; bla2; bla3; ... ); which looks *somewhat* natural if you read the parens as braces. (Of course, if you use a ',' that cpp parses as an argument separator (e.g. if(z) y=3,z=4) you are going to get cpp error messages... Another potential problem is too long an argument list. Since first-time only code is usually fairly short, this won't be much of a problem.) Dave Olson, Fortune Systems