Just to follow up on the C++ sized enum: the bug with the underlying
type has been fixed and will show up in the next release.

-----Original Message-----
From: Richard Grimes [mailto:[EMAIL PROTECTED]] 
Sent: Sunday, May 05, 2002 4:00 AM
To: [EMAIL PROTECTED]
Subject: Re: [DOTNET] Schrodininger's Enum

Hmmm,

Its been a while since I did any quantum mechanics[1], semiconductor
research was just too much hard work, so I moved to software development
to
take a rest ;-). I think you'll find the answer to your question lies in
the
class heirarchy. An enum derives from System::Enum, which derives from
System::ValueType. So this makes an enum a value type. The ECMA spec
says
this:

"An enum, short for enumeration, defines a set of symbols that all have
the
same type.  A type shall be an enum if and only if it has an immediate
base
type of System.Enum.  Since System.Enum itself has an immediate base
type of
System.ValueType (see Partition IV), enums are value types (see Chapter
12).
"[2]

Also note that value types can be created on the stack and this is the
case
with enums - you do not use the managed new operator. (Actually I
dislike
the way that C# blurs the use of new, I think that you should be able to
call a ctor of a value type directly, just as you do in C++. The fact
that
C# makes you use new when calling the ctor of a value type confuses the
issue IMO.) Indeed, C++ is explicit in this respect, you declare a .NET
enum
with the __value keyword and if you try to create an instance with __gc
new
the compiler will generate an error. You could say that an enum is just
a
collection of named integral values,

When you declare an enum it looks like you are deriving from an integral
type, but this is just a trick that compilers play on you, you are
merely
telling the compiler the type on which the enum is based.
Incidentally, the type of an enum highlights a bug in the C++ compiler.
If
you do this in C#:

enum X : long {ONE};

you get a class derived from System::Enum with a member called value__
that
is int64, the C# compiler will make the value__ member the type you
specify
in the declaration of the enum. If you do this in C++:

__value enum X : __int64 {ONE};

you get a class derived from System::Enum with a member called value__,
but
regardless of the type you specify, value__ is always int32. Which is
not
what you want.

So in summary, an enum is essentially a collection of named values, and
so
it is a value type.

Richard

[1] "FIR Studies of III-V Semiconductor Structures", 1990
www.grimes.demon.co.uk/thesis/Firsumm.htm
[2] Common Language Infrastructure, Partition II Metadata

----- Original Message -----
From: "Ray Heath" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Saturday, May 04, 2002 11:50 PM
Subject: [DOTNET] Schrodininger's Enum


Visual Studio MSDN Help Wrote:

"An Enum is a named constant whose underlying type is any integral type
except Char. If no underlying type is explicitly declared, Int32 is
used.
Enum DERIVES FROM VALUETYPE, BUT IS NOT A VALUE TYPE. Programming
languages
typically provide syntax to declare an enumeration that consists of a
set
of named constants and their values." [1]

Although a 'String Theory' kind of guy, I am not completely familiar
with
Quantum Object-Oriented Value/Non-Value Types. Is the upper-case type in
the above paragraph accurate? If so, could someone point me to a clear
explaination?

Much of the literature seems to claim that Enum is indeed a value type
(though not a primitive value type). [2]


Thanks - Ray
www.rayheath.com


[1] ms-help://MS.VSCC/MS.MSDNVS/cpref/html/frlrfsystemenumclasstopic.htm
[2] e.g. Pattison, Ted. "Basic Instincts: Objects and Values Part 1."
(See
Figure 2) MSDN Magazine. June 2002: 115

You can read messages from the DOTNET archive, unsubscribe from DOTNET,
or
subscribe to other DevelopMentor lists at http://discuss.develop.com.

You can read messages from the DOTNET archive, unsubscribe from DOTNET,
or
subscribe to other DevelopMentor lists at http://discuss.develop.com.

You can read messages from the DOTNET archive, unsubscribe from DOTNET, or
subscribe to other DevelopMentor lists at http://discuss.develop.com.

Reply via email to