------- Comment #2 from sergstesh at yahoo dot com  2009-05-12 15:43 -------
No, the documentation explicitly says

( http://gcc.gnu.org/onlinedocs/gcc-4.3.3/gcc.pdf , page 247 .. 248):

"
5.3 Labels as Values
...
   To use these values, you need to be able to jump to one. This is done with
the computed
goto statement1 , 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 };
  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 well.
   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 may not 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.
   An alternate way to write the above example is
       static const int array[] = { &&foo - &&foo, &&bar - &&foo,
                                    &&hack - &&foo };
       goto *(&&foo + array[i]);
",

i.e. the documentation explicitly allows to rely upon labels as values.

I actually checked putting label addresses into an array - the same problem. I
didn't publish the code here - didn't want to over-complicate the test case.


-- 

sergstesh at yahoo dot com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |UNCONFIRMED
         Resolution|INVALID                     |


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40115

Reply via email to