Re: Token is an int ?
Stefan Seefeld <[email protected]> Sat, 17 Mar 2007 14:11:59 -0400
| Newsgroups | gmane.comp.documentation.synopsis |
|---|---|
| Message-ID | <[email protected]> |
David Genest wrote:
> Hi,
>
> Is there a reason why the Type member of the Token struct
> (/src/Synopsis/Token.hh) is an opaque int instead of the name of the
> enum?
>
> I am using visual studio to compile the core synopsis library, and
> this environment is able to display enum values when debugging, which
> helps alot when stepping through the lib. I have modified the
> corresponding sources and everything works like expected.
>
> So, instead of having:
>
> struct Token
> {
> typedef int Type;
> enum
> {
> Identifier = 258, //.< The first 256 are representing character
> literals.
> Constant,
> CharConst,
> ...
> }
> };
As the comment above says, characters represent themselves, i.e. you can say:
Token::Type token = 'a';
The conversion from character to int is implicit. However, there is no
standard conversion from char to enum, i.e. the above wouldn't be possible
if Token::Type was an enumeration type.
(If MSVC allows an implicit conversion from character types to an enum type,
it is wrong. (See section 4.7 of the spec.)
Regards,
Stefan
--
...ich hab' noch einen Koffer in Berlin...