Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2 9/18/84; site sdcrdcf.UUCP Path: utzoo!watmath!clyde!burl!ulysses!allegra!mit-eddie!genrad!decvax!ittvax!dcdwest!sdcsvax!sdcrdcf!brad From: brad@sdcrdcf.UUCP (Brad Spear) Newsgroups: net.lang.c Subject: Re: on1 construct Message-ID: <1448@sdcrdcf.UUCP> Date: Wed, 7-Nov-84 14:03:04 EST Article-I.D.: sdcrdcf.1448 Posted: Wed Nov 7 14:03:04 1984 Date-Received: Fri, 9-Nov-84 08:53:06 EST References: <124@cadvax> Reply-To: brad@sdcrdcf.UUCP (Brad Spear) Organization: System Development Corp. R+D, Santa Monica Lines: 52 Summary: In article <124@cadvax> jacob@cadvax.UUCP (Jacobo Bulaevsky) writes: >I've started functions in the following way: > >function () >{ > static char first_time_in = TRUE; > > if (first_time_in) { > first_time_in = FALSE; > bla, bla, bla... > }; > > etc... >} Your letter got me to thinking, I have to start some procedures that way also. The following is what I came up with. I tested it with the simple program that follows, and it appeared to work, so we'll see. #define TRUE 1 #define FALSE 0 #define ON_FIRST_TIME static char _done = FALSE; if (!_done && (_done=TRUE)) main() { int j; for (j = 0; j < 3; j++) sub(); } sub() { ON_FIRST_TIME printf ("inside init\n"); printf("routine call\n"); } Note that ON_FIRST_TIME would be treated like any 'if' statement, so just put in some '{}', and off you go. The only restriction is that it must be the first expression in a block, because of the declaration of done. Note that if the expression "!_done" evaluates to FALSE, which it does after the first time, the expression "(_done=TRUE)" will not be re-evaluated. If you want an expression that doesn't use a hidden variable, you might try this one, although I haven't tested it. #define ON_FIRST_TIME(x) if (!(x) && ((x)=TRUE)) In this case, the variable used for x would already have to be declared, but it also allows the macro to be used anywhere. Brad Spear sdcrdcf!brad