Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.1 6/24/83 (MC840302); site diku.UUCP Path: utzoo!watmath!clyde!burl!ulysses!mhuxr!mhuxt!houxm!whuxl!whuxlm!akgua!gatech!seismo!mcvax!diku!thorinn From: thorinn@diku.UUCP (Lars Henrik Mathiesen) Newsgroups: net.lang.c Subject: Re: mildly (sic) obfuscating c (really style) Message-ID: <21@diku.UUCP> Date: Fri, 20-Dec-85 21:04:30 EST Article-I.D.: diku.21 Posted: Fri Dec 20 21:04:30 1985 Date-Received: Sun, 22-Dec-85 00:52:25 EST References: <564@puff.UUCP> <979@rlvd.UUCP> Distribution: net Organization: DIKU, U of Copenhagen, DK Lines: 43 In article <564@puff.UUCP> tom@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