new do-while syntax

Mikael Pettersson mikpe at mina.liu.se
Tue Dec 20 13:02:59 AEST 1988


In article <8562 at alice.UUCP> ark at alice.UUCP (Andrew Koenig) writes:
>[edited]
>I can't use arbitrary statements with the comma operator:
>    do {
>	[read & munge & set status]
>    } while (status) {
>	for (i = 0; i < THINGSIZE; i++)
>	    if (temp[i] != precious[i])
>		printf ("munge changed element %d of line %d\n", i, count);
>    }

Watch:
     #include <setjmp.h>
     ...
     jmp_buf kappa;
     do {
	[read & munge & set status]
     } while(status &&
	      (i=0,
	       setjmp(kappa),
	       i<THINGSIZE &&
		 (temp[i]!=precious[i] &&
		    printf("munge changed element %d of line %d\n", i, count),
		  ++i,	
		  longjmp(kappa) ),
	       1 )
	    );

Compiles and runs just fine :-)

>As I said before, it's way too late to get anything like this
>into C now.  It's fun to think about, though.

Agreed.
BTW, I came up with the ideas for the above hack when I tried to figure out
a way to implement an `expression language' by translating it to plain old C.
It isn't pretty, but it would do if all you want is a quick and dirty
implementation of the new language.
-- 
Mikael Pettersson, Dept of Comp & Info Sci, University of Linkoping, Sweden
email: mpe at ida.liu.se  or  ..!{mcvax,munnari,uunet}!enea!liuida!mpe



More information about the Comp.lang.c mailing list