Address of a goto label?

Robert Seals rds95 at leah.Albany.Edu
Wed Apr 19 03:39:00 AEST 1989


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



More information about the Comp.lang.c mailing list