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

enum{f,g=f};

0 views
Skip to first unread message

Francois Grieu

unread,
Jan 6, 2010, 3:23:39 AM1/6/10
to
Hi, is this valid?

enum{f,g=f};

The problem (if any) is that the value for g references f,
which is defined in an enum not yet completed.

TIA,
Francois Grieu

John

unread,
Jan 6, 2010, 3:36:30 AM1/6/10
to

f == 0
g == 0

Keith Thompson

unread,
Jan 6, 2010, 3:55:10 AM1/6/10
to
Francois Grieu <fgr...@gmail.com> writes:
> Hi, is this valid?
>
> enum{f,g=f};
>
> The problem (if any) is that the value for g references f,
> which is defined in an enum not yet completed.

Yes, it's valid.

C99 6.2.1p7:

Each enumeration constant has scope that begins just after the
appearance of its defining enumerator in an enumerator list.

Note that an "enumerator" includes the "= constant" if present, so
"enum { x = x }" is illegal (unless another x was previously declared
in an enclosing scope, but that's ugly so don't do it).

--
Keith Thompson (The_Other_Keith) ks...@mib.org <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"

Francois Grieu

unread,
Jan 6, 2010, 5:10:27 AM1/6/10
to
Keith Thompson wrote :

> Francois Grieu <fgr...@gmail.com> writes:
>> Hi, is this valid?
>>
>> enum{f,g=f};
>>
>> The problem (if any) is that the value for g references f,
>> which is defined in an enum not yet completed.
>
> Yes, it's valid.
>
> C99 6.2.1p7:
>
> Each enumeration constant has scope that begins just after the
> appearance of its defining enumerator in an enumerator list.
>
> Note that an "enumerator" includes the "= constant" if present, so
> "enum { x = x }" is illegal (unless another x was previously declared
> in an enclosing scope, but that's ugly so don't do it).
>
Thanks, that's exactly the reference & explanation that I was seeking.

Francois Grieu

0 new messages