mildly obfuscating c

tom at puff.UUCP tom at puff.UUCP
Sat Dec 7 08:54:16 AEST 1985


ok, guys, now i will admit that the below code is *not* kosher. 
but the question still remains, if you run this program, what will
your output be?  does the machine you compile it on make
a difference?  does defining ARG to be something, say 999,
make a difference?   what if VAR were auto or static?

-------------------------------------------------------------
# define ARG
# define VAR register
# define CALL(x) (*(int (*)()) (x))(ARG)

main() {
    VAR thing = 0;
stuff:
    printf("here it goes, thing is %d\n",thing);
    if (!thing++) 
        CALL(stuff);
    printf("one there it went, thing is %d\n",thing);
    printf("two there it went, thing is still %d\n",thing);
}


/* lint outputs
test.c:
test.c(8): warning: questionable conversion of function pointer
*/
-------------------------------------------------------------

note the lint output.  no kidding.


on a vax, i get a reserved intruction trap as soon as i call the
label.  on a gould, the program runs normally, but i get this:

-------------------------------------------------------------
here it goes, thing is 0
here it goes, thing is 1
here it goes, thing is 1
two there it went, thing is still 2
-------------------------------------------------------------

which is quite interesting.  the third line has the wrong string
on the stack at the time.  

on a pyramid, this is the bizarre result:

-------------------------------------------------------------
here it goes, thing is 0
here it goes, thing is 536151860
one there it went, thing is 536151861
two there it went, thing is still 536151861
one there it went, thing is 1
two there it went, thing is still 1
-------------------------------------------------------------


i haven't been able to figure out anyway to "goto" a label that
i don't know.  for example, i would like to do this:

-------------------------------------------------------------
main() {
	int (*jump[])() = { l1,l2,l3,l4,l5,l6,l7,l8 }

	l1: /* code */
	l2: /* code */
	l3: /* code */
	l4: /* code */
	l5: /* code */
	l6: /* code */
	l7: /* code */
	l8: /* code */

	goto *jump[whatever]
}
-------------------------------------------------------------

aside from the forward-referencing problem of the unseen labels, 
this is a still syntax error.   anyone have any way to do this?


tom



More information about the Comp.lang.c mailing list