Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c++ > #8090 > unrolled thread
| Started by | Philipp Kraus <philipp.kraus@flashpixx.de> |
|---|---|
| First post | 2011-07-22 18:52 +0200 |
| Last post | 2011-07-22 16:37 -0700 |
| Articles | 6 — 5 participants |
Back to article view | Back to comp.lang.c++
enum escaping keywords Philipp Kraus <philipp.kraus@flashpixx.de> - 2011-07-22 18:52 +0200
Re: enum escaping keywords "Balog Pal" <pasa@lib.hu> - 2011-07-22 19:19 +0200
Re: enum escaping keywords Philipp Kraus <philipp.kraus@flashpixx.de> - 2011-07-22 19:35 +0200
Re: enum escaping keywords Victor Bazarov <v.bazarov@comcast.invalid> - 2011-07-22 13:52 -0400
Re: enum escaping keywords James Kanze <james.kanze@gmail.com> - 2011-07-22 13:02 -0700
Re: enum escaping keywords "James" <no@spam.invalid> - 2011-07-22 16:37 -0700
| From | Philipp Kraus <philipp.kraus@flashpixx.de> |
|---|---|
| Date | 2011-07-22 18:52 +0200 |
| Subject | enum escaping keywords |
| Message-ID | <j0c9t4$e8p$1@online.de> |
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
[toc] | [next] | [standalone]
| From | "Balog Pal" <pasa@lib.hu> |
|---|---|
| Date | 2011-07-22 19:19 +0200 |
| Message-ID | <j0cbg0$2519$1@news.ett.com.ua> |
| In reply to | #8090 |
"Philipp Kraus" <philipp.kraus@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, ...
[toc] | [prev] | [next] | [standalone]
| From | Philipp Kraus <philipp.kraus@flashpixx.de> |
|---|---|
| Date | 2011-07-22 19:35 +0200 |
| Message-ID | <j0ccd8$gdh$1@online.de> |
| In reply to | #8091 |
On 2011-07-22 19:19:31 +0200, Balog Pal said:
> "Philipp Kraus" <philipp.kraus@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 !? 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
[toc] | [prev] | [next] | [standalone]
| From | Victor Bazarov <v.bazarov@comcast.invalid> |
|---|---|
| Date | 2011-07-22 13:52 -0400 |
| Message-ID | <j0cdd5$t77$1@dont-email.me> |
| In reply to | #8094 |
On 7/22/2011 1:35 PM, Philipp Kraus wrote:
> On 2011-07-22 19:19:31 +0200, Balog Pal said:
>
>> "Philipp Kraus" <philipp.kraus@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
[toc] | [prev] | [next] | [standalone]
| From | James Kanze <james.kanze@gmail.com> |
|---|---|
| Date | 2011-07-22 13:02 -0700 |
| Message-ID | <9ed43b07-3437-4ed8-a25d-cf62520f47dd@m18g2000vbl.googlegroups.com> |
| In reply to | #8090 |
On Jul 22, 5:52 pm, Philipp Kraus <philipp.kr...@flashpixx.de> wrote:
> 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 ?
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
[toc] | [prev] | [next] | [standalone]
| From | "James" <no@spam.invalid> |
|---|---|
| Date | 2011-07-22 16:37 -0700 |
| Message-ID | <j0d1ig$4f4$1@speranza.aioe.org> |
| In reply to | #8090 |
"Philipp Kraus" <philipp.kraus@flashpixx.de> wrote in message
news:j0c9t4$e8p$1@online.de...
> 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 ?
struct lang {
enum instruction {
EN,
IT,
DE,
ASM,
OR
};
};
?
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.c++
csiph-web