rds95@leah.Albany.Edu (Robert Seals) (04/19/89)
Hi again,
A quote from Ken Arnold's April 1989 "C Advisor" column in Unix Review:
...you can take the address of
a goto label and start stuffing
data into it.
Well, the whole article was tongue-in-chic, and in fact included a reference
that said,
...write a column which _looked_
normal, but actually contained
some harmless misinformation...
So, the idea of taking the address of a goto label seemed thrilling, and
I wrote a program to test it. Thus,
#include <stdio.h>
main()
{
int *p;
HERE:
p = &HERE;
printf("%d\n", p);
}
But it don't verk; at least, the FIRST system I tested it on didn't verk.
The error was "undefined symbol" when taking the address of HERE. So, I
checked K&R2, which says:
The only use of an identifier
label is as a target of goto.
So, the failed compilation seemed correct. BUT, I tried it on the local
4.3-tahoe, and it compiled, and gave a warning about taking the address
of an array or function, and the & would be ignored, and it ran and the
program printed "76\n" (unoptimized). So I tried it on good old Ultrix
1.2 cc, and got the same as 4.3, except that I got 80 instead of 76.
And then gcc said "undeclared variable."
So I guess that this is an ANSI thingy-doo, and the answer I will get is,
"it's grotesque, but it works on old compilers" to the question (what is
this, Jeopardy?) "what is the deal here, anyway?"
rob
dg@lakart.UUCP (David Goodenough) (04/20/89)
From article <1768@leah.Albany.Edu>, by rds95@leah.Albany.Edu (Robert Seals): > I wrote a program to test it. Thus, > ..... > HERE: > p = &HERE; > ..... > > So, the failed compilation seemed correct. BUT, I tried it on the local > 4.3-tahoe, and it compiled ..... Ugh. The possibilities for high level self modifying code are horrific. :-) One thing that I _DID_ like about BCPL was that you could do the following: foo() { code; } boo() { different code; } zap() { foo(); foo = boo; foo(); /* but he really calls boo() */ } Made for a really funky node allocation subroutine in a lisp like environment :-) We now return you to more civilised C programming. -- dg@lakart.UUCP - David Goodenough +---+ IHS | +-+-+ ....... !harvard!xait!lakart!dg +-+-+ | AKA: dg%lakart.uucp@xait.xerox.com +---+