on1 construct

Brad Spear brad at sdcrdcf.UUCP
Thu Nov 8 06:18:08 AEST 1984


Silly me. If I had thought about it for 10 more minutes, I would have had a
better version the first time.  In this case, the _f doesn't have to be
negated every time. I thought I had ruled this case out, but I made a mistake
somewhere originally, and it does work.  Note that it depends on the fact
that "_f" is evaluated before "!(_f=FALSE)", which is what C is supposed to
guarantee.

#define ON_FIRST_TIME   static char _f = TRUE; if (_f && !(_f=FALSE))

This expression can be used like:

{       declarations ...

	ON_FIRST_TIME
	  {
	  blah1, blah1, blah1 ...
	  }
	blah2, blah2, blah2 ...
}

It will cause "blah1, blah1, blah1 ..." to be executed the first time only.

It would be nice if someone could figure out how to make a non-function block
return a value, then the expression could go anywhere, and the _f could be
totally invisible.

Brad Spear
sdcrdcf!brad



More information about the Comp.lang.c mailing list