🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

2 total messages Started by raviyer Sat, 16 Mar 1996 06:04
enums and conversion question
#3689
Author: raviyer
Date: Sat, 16 Mar 1996 06:04
36 lines
1906 bytes
Hi,

I have the following piece of code,

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?

thanks in advance
-- 
|#include <stddisclaimers.h> // My own views                                |
|Ravikant Iyer. aka - ravi - raviyer@nt.com                                 |
|Nortel. Santa Clara CA. Off: 408-565-7430                                  |
|                               ESN-655-7430.                               |
---
[ comp.std.c++ is moderated.  To submit articles: try just posting with      ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu         ]
[ FAQ:      http://reality.sgi.com/employees/austern_mti/std-c++/faq.html    ]
[ Policy:   http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu                             ]
Re: enums and conversion question
#3711
Author: 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 
]
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads