[LCP]Address of a label
Chirag Kantharia
chyrag at yahoo.com
Thu Feb 21 20:33:43 UTC 2002
Hello,
Is it possible to get address of a label, from within a C program? What
I want to do is the following:
I have a huge switch() statement, which looks like this:
switch(*pc)
{
case 1:
do_something1;
break;
case 2:
do_something2;
break;
...
}
Since my switch is really huge (close to 200 cases), I was wondering if
it were possible to optimize it, by storing labels in an array.
struct label array[NO_OF_CASES];
and "goto array[*pc].label;"
(I know the syntax is wrong, but I hope I get the idea across).
I know it's possible with function pointers, but I will have to convert
all the do_somethings to functions.
void (*do_something1)(void)
{
}
void (*do_something2)(void)
{
}
struct label {
void (*f)(void);
};
And, I simply use
array[*pc].f();
(Of course, there's an assumption that the cases are sequential: they go
from 1, 2, 3.. 200).
I want to know if it's possible using labels. And if yes, then how.
chyrag.
--
Chirag Kantharia, symonds.net/~chyrag/
Linux scrooge 2.4.17 #1 Wed Jan 16 17:07:25 IST 2002 i686 unknown
More information about the linuxCprogramming
mailing list