[tree-ssa] Computed gotos
Jamie Lokier
jamie@shareable.org
Fri Jul 4 02:01:00 GMT 2003
Segher Boessenkool wrote:
> Robert Dewar wrote:
> >OK, my confusion then sorry. Why on earth is the C version called a
> >computed
> >goto, that sure is a confused terminology, but I guess one that is familiar
> >in the GNU C world. I will take off my Fortran hat :-)
>
> The manual says:
>
> "The analogous feature in Fortran is called an assigned goto,
> but that name seems inappropriate in C, where one can do more
> than simply store label addresses in label variables."
>
> Not that I can see what more that could be (unless undefined
> behaviour is allowed).
Dubious, but works:
#include <stdint.h>
#include <stdio.h>
int main ()
{
uintptr_t label = (uintptr_t) &&label1;
uintptr_t flip = (uintptr_t) &&label1 ^ (uintptr_t) &&label2;
for (int i = 0; i < 10; i++, label ^= flip)
{
goto *(void *) label;
label1:
printf ("red\n");
continue;
label2:
printf ("green\n");
}
return 0;
}
More information about the Gcc
mailing list