mildly (sic) obfuscating c (really style)

Lars Henrik Mathiesen thorinn at diku.UUCP
Sat Dec 21 12:04:30 AEST 1985


In article <564 at puff.UUCP> tom at puff.UUCP writes:
[describes code using a label as a function address,
 and the various results on different machines]

  Well, ON A VAX, all you have to do is to put in the register save
mask (well, it was you who started doing assemblerish things in C :-).

-------------------------------------------------------
main() {
	register thing = 0;

	if (0) {			/* skip mask on first entry */
stuff:		;
		asm(".word	0x800");	/* save r11 (thing) */
		;
	}
	printf("Here it goes, thing is %d\n", thing);
	if (!thing++)
		(*(int(*)())stuff)();
	printf("There it went (one), thing is %d\n", thing);
	printf("There it went (two), thing is still %d\n", thing);
}
-------------------------------------------------------

  The results are relatively unsurprising:

-------------------------------------------------------
Here it goes, thing is 0
Here it goes, thing is 1
There it went (one), thing is 2
There it went (two), thing is still 2
There it went (one), thing is 1
There it went (two), thing is still 1
-------------------------------------------------------

  Remarks: R11 is saved at label stuff because that's what C does at
entry to main; if you don't save it, the two last lines read 2 instead.
Don't use cc -O, as this gets you an undefined label in `as'.

  Maybe this shows that the conceptual model behind C looks like a VAX;
but then maybe we knew that already.
--
Lars Mathiesen, DIKU, Copenhagen, Denmark	..!mcvax!diku!thorinn



More information about the Comp.lang.c mailing list