[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[DotGNU][PNET]/[PNET/C]Request for Feature "Labels as Values" in Pnet/C

From: James Michael DuPont
Subject: [DotGNU][PNET]/[PNET/C]Request for Feature "Labels as Values" in Pnet/C
Date: Sat, 9 Aug 2003 08:28:15 -0700 (PDT)

Dear Pnet Hackers, 

I would like to request that the following GCC language feature be
considered for the pnet/C language  : "Labels as Values"

It is used by many languge tools and interpreters.

Is there anyone working on it, or any plans for its support?

Labels as Values

You can get the address of a label defined in the current function (or
a containing function) with the unary operator `&&'. The value has type
void *. This value is a constant and can be used wherever a constant of
that type is valid. For example:

void *ptr;
ptr = &&foo;

To use these values, you need to be able to jump to one. This is done
with the computed goto statement(2), goto *exp;. For example,

goto *ptr;

Any expression of type void * is allowed.

One way of using these constants is in initializing a static array that
will serve as a jump table:

static void *array[] = { &&foo, &&bar, &&hack 2;

Then you can select a label with indexing, like this:

goto *array[i];

Note that this does not check whether the subscript is in bounds--array
indexing in C never does that.

Such an array of label values serves a purpose much like that of the
switch statement. The switch statement is cleaner, so use that rather
than an array unless the problem does not fit a switch statement very

Another use of label values is in an interpreter for threaded code. The
labels within the interpreter function can be stored in the threaded
code for super-fast dispatching.

You can use this mechanism to jump to code in a different function. If
you do that, totally unpredictable things will happen. The best way to
avoid this is to store the label address only in automatic variables
and never pass it as an argument. 

James Michael DuPont

Do you Yahoo!?
Yahoo! SiteBuilder - Free, easy-to-use web site design software

reply via email to

[Prev in Thread] Current Thread [Next in Thread]