Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2 9/18/84; site rlvd.UUCP Path: utzoo!watmath!clyde!burl!ulysses!allegra!mit-eddie!genrad!panda!talcott!harvard!cmcl2!seismo!mcvax!ukc!warwick!rlvd!asw From: asw@rlvd.UUCP (Antony Williams) Newsgroups: net.lang.c Subject: Re: mildly (sic) obfuscating c (really style) LONG Message-ID: <979@rlvd.UUCP> Date: Fri, 13-Dec-85 13:41:23 EST Article-I.D.: rlvd.979 Posted: Fri Dec 13 13:41:23 1985 Date-Received: Sun, 22-Dec-85 00:10:24 EST References: <564@puff.UUCP> Reply-To: asw@rlvd.UUCP (Antony Williams) Distribution: net Organization: Rutherford Appleton Laboratory, Atlas Buildings, U.K. Lines: 107 Summary: do it in private, and wash your hands afterwards Xpath: warwick ubu In article <564@puff.UUCP> tom@puff.UUCP writes: >ok, guys, now i will admit that the below code is *not* kosher. ^^^^^^ I don't know what you mean by kosher, but it is clear to me that in no way is the code defined to mean anything. >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, ^^^^^^^^^^ ^^^^^^^^^^^^ you bet. no point >make a difference? what if VAR were auto or static? ^^^^^^^^^^^^^^ entirely irrelevant. > >------------------------------------------------------------- ># 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. what does the compiler do? Any compiler worth its salt should refuse to generate anything executable. This is C code, not assembler. >on a vax, (description of what various machines do) >------------------------------------------------------------- Anything you get is what the program deserves. Nowhere have I seen any statement to the effect that labels can be used for anything other than simple goto's. Most of the computing community tends to use labels with discretion, if at all. They are not normally considered to be fair game as values of variables. > > >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: ^^^^^^^^^^ If you don't know where it is going, how do you know that the program is going top behave the way you want (only mildly sarcastic :-) > >------------------------------------------------------------- >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] >} the right way to do this is switch(whatever) { 0: /* code for l1 */ 1: /* code for l2 */ etc } if you want to do it twice, put a loop around it, with the appropriate values of "whatever". >------------------------------------------------------------- > >aside from the forward-referencing problem of the unseen labels, >this is a still syntax error. anyone have any way to do this? I can only assume you are a refugee from FORTRAN, where such things used to be normal. If you ever write such a program in C, please keep it to yourself. Even Fortran is beginning to see the error of its ways, and "deprecating" such usage. -- --------------------------------------------------------------------------- Tony Williams |Informatics Division UK JANET: asw@uk.ac.rl.vd |Rutherford Appleton Lab Usenet: {... | mcvax}!ukc!rlvd!asw |Chilton, Didcot ARPAnet: asw%rl.vd@ucl-cs.arpa |Oxon OX11 0QX, UK