mildly (sic) obfuscating c (really style) LONG
Antony Williams
asw at rlvd.UUCP
Sat Dec 14 04:41:23 AEST 1985
In article <564 at puff.UUCP> tom at 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 at uk.ac.rl.vd |Rutherford Appleton Lab
Usenet: {... | mcvax}!ukc!rlvd!asw |Chilton, Didcot
ARPAnet: asw%rl.vd at ucl-cs.arpa |Oxon OX11 0QX, UK
More information about the Comp.lang.c
mailing list