Is it possible to generate unique goto labels with preprocessor?
Salim Nasser
salim@windriver.com
Wed May 16 17:44:00 GMT 2001
> Is it possible with this way, or other, to generate unique goto labels with
> the preprocessor?
Actually it is, but you need a couple of levels of indirection:
#define __UNIQUE_LABEL(x) label ## x
#define _UNIQUE_LABEL(y) __UNIQUE_LABEL(y)
#define UNIQUE_LABEL _UNIQUE_LABEL(__LINE__)
I can't find a way to do it with fewer than three #defines ;)
---------------------------------------
Salim Nasser
Software Developer
Wind River Systems
300 Wind River Way, Alameda, CA
email: salim.nasser@windriver.com
---------------------------------------
Anders Torger writes:
>
> I'm making a hack which require a macro to generate goto labels (I can of
> course provide the label as an argument to the macro, but that significantly
> reduces the maintainability of the resulting code).
>
> My idea was to do like this:
>
> label ## __LINE__:
>
> but then I just get
>
> label__LINE__:
>
> after the preprocessor has done its work, and I would like to have
>
> label897:
>
> if the line number happened to be 897.
>
> Is it possible with this way, or other, to generate unique goto labels with
> the preprocessor?
>
> Please answer to me directly, since I'm currently not on the list.
>
> /Anders Torger
>
More information about the Gcc
mailing list