🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c++
Article #3711

Re: enums and conversion question

#3711
From: Steve Clamage
Date: Mon, 18 Mar 1996 17:45
40 lines
2219 bytes
raviyer@nt.com writes:

>void goo(int);
>void goo(unsigned int);

>enum Enum {E1,E2}

>void foo ()
>{
>	Enum e = E1;
>	goo(e); // Is this call ambiguos?
>}

>The DWP in 4.5 (integral promotion) point 2 says that 
>"An rvalue of type wchar_t or an enumeration type can be converted to an
>rvalue of the _first_ of the following types that can represent all the values
>of the source type: int, unsigned int, long, unsigned long."

>Does this mean that in the above example the call to goo(e) should be resolved
>to goo(int)? or in other words is the promotion enum -> int better than 
>enum -> unsigned int in this case?

Yes, although your "other words" are not quite correct.

If the range of an enum type can be represented by type int, values
of that type undergo promotion to int, and not to any other type.
Thus, calling goo(int) requires only a promotion to int (since the
values 0 and 1 can always be represented by type int), while calling
goo(unsigned int) requires a standard conversion. A promotion is
preferred over a conversion, so the call is not ambiguous.

--
Steve Clamage, stephen.clamage@eng.sun.com
---
[ comp.std.c++ is moderated.  To submit articles: Try just posting with your 
                newsreader.  If that fails, use mailto:std-c++@ncar.ucar.edu
  comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
  Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
  Comments? mailto:std-c++-request@ncar.ucar.edu 
]
Technical Details
Message-ID: <4ihe7k$1cu@engnews1.Eng.Sun.COM>
Path: arc1-ca.pugleaf.net!chronicle.mti.sgi.com!austern
References: <4icihu$e3d@nrchh52.rich.nt.com>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!chronicle.mti.sgi.com!austern
From: clamage@Eng.Sun.COM (Steve Clamage)
Newsgroups: comp.std.c++
Subject: Re: enums and conversion question
Date: 18 Mar 1996 09:45:00 PST
Organization: Sun Microsystems Inc., Mountain View, CA
Approved: austern@isolde.mti.sgi.com
Message-ID: <4ihe7k$1cu@engnews1.Eng.Sun.COM>
References: <4icihu$e3d@nrchh52.rich.nt.com>
NNTP-Posting-Host: isolde.mti.sgi.com
X-Original-Date: 17 Mar 1996 16:22:12 GMT
X-Newsreader: NN version 6.5.0 #21 (NOV)
X-Auth: PGPMoose V1.1 PGP comp.std.c++
 iQBVAwUBMU2hd0y4NqrwXLNJAQGlXAIAmkl4i2IY79diEM+rgBiZsIhWG8qXoWl+
 A76mS0uV8OZmZo3hBQijx0TQZZV5ql3+q+O2RV7WkIkshuBI9kneDg==
 =5afj
Originator: austern@isolde.mti.sgi.com