Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

enum escaping keywords

5 views
Skip to first unread message

Philipp Kraus

unread,
Jul 22, 2011, 12:52:52 PM7/22/11
to
Hello,

I create a enum type with language codes like:
enum lang {
en,
it,
de,
asm,
or
}

but some codes are keywords (asm, or). How can I escape them, so that I
can use them like
lang::or or lang::asm ?

Thanks

Phil

Balog Pal

unread,
Jul 22, 2011, 1:19:31 PM7/22/11
to
"Philipp Kraus" <philip...@flashpixx.de>

Those are reserved words. You can not use them as identifiers. chose a
different form like Asm, asm_, l_asm, ...

Philipp Kraus

unread,
Jul 22, 2011, 1:35:36 PM7/22/11
to

Is there no other solution !? Because the language codes are defined in
the ISO 639, so I would like to use the defined
codes as a enum value. I wouldn't create a own value

Thx

Phil

Victor Bazarov

unread,
Jul 22, 2011, 1:52:37 PM7/22/11
to
On 7/22/2011 1:35 PM, Philipp Kraus wrote:
> On 2011-07-22 19:19:31 +0200, Balog Pal said:
>
>> "Philipp Kraus" <philip...@flashpixx.de>
>>> I create a enum type with language codes like:
>>> enum lang {
>>> en,
>>> it,
>>> de,
>>> asm,
>>> or
>>> }
>>>
>>> but some codes are keywords (asm, or). How can I escape them, so that
>>> I can use them like
>>> lang::or or lang::asm ?
>>
>> Those are reserved words. You can not use them as identifiers. chose a
>> different form like Asm, asm_, l_asm, ...
>
> Is there no other solution !?

<shrug> There probably is. Instead of introducing an identifier that
is illegal because it's a keyword, you could introduce a string literal...

> Because the language codes are defined in
> the ISO 639, so I would like to use the defined
> codes as a enum value. I wouldn't create a own value

<shrug again> I would like my variables to be named 'new', 'delete',
and 'for'. I can't, however. So?

V
--
I do not respond to top-posted replies, please don't ask

James Kanze

unread,
Jul 22, 2011, 4:02:11 PM7/22/11
to

You can't. Note too that enum's don't introduce a new scope (at
least not in current C++), your enum introduces the keywords in
global scope.

The traditional solution to this is to use a simple prefix:

enum lang {
lang_en,
lang_it,
lang_de,
lang_asm,
lang_or
};

or something like that.

--
James Kanze

James

unread,
Jul 22, 2011, 7:37:17 PM7/22/11
to
"Philipp Kraus" <philip...@flashpixx.de> wrote in message
news:j0c9t4$e8p$1...@online.de...


struct lang {
enum instruction {
EN,
IT,
DE,
ASM,
OR
};
};


?


0 new messages