on1 construct
Dave Olson
olson at fortune.UUCP
Tue Nov 6 07:41:17 AEST 1984
In article <124 at cadvax> jacob at 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
More information about the Comp.lang.c
mailing list