[Mono-list] Enum problem

gennady wexler adyler@winisp.net
Sat, 16 Oct 2004 11:52:00 -0700

I think what we wanted to know was why based on different execution sources
we get:

case 1: Negativo prints first
case 2: Neutro prints first

it appears they are aligned differently by compiler (jit in this case).

it is not a question anymore whether these two values are of the same

there are attributes you can specify for enum declaration, I think mono
defaults to something different than what .net does.

it doesn't hurt final product here though, program wont break in such cases=
it will just behave differently than what coder expects it to. :)

we are just being a bit too perfectionist here, we want print out look
exactly the same as it comes out from under .net environment.

so to write this code cleanly you would have to use recommended practices,
that is it would be something like this:

enum EnumVal {
    enFirstValue =3D 1,
    enThirdValue =3D 20,

this way compilers will take care of assigning unique values to each of the
values, then your code will behave as you expect it to.

now, to make the original code in this mail thread to work, you will need t=
tell compiler the base type of enum construct:

enum DoubleEnumVal : double { // or whatever type you want
    enFirstVal =3D .3, // or I presume 1/3 should also work

however, I almost never see anyone had a need for this kind of precision,
have you?

so there really is no problem here, just matter of proper use of the

does this make sense?

On 10/16/04 11:28 AM, "Kirk Marple" <kirk-public@agnostic-media.com> wrote:

> The real issue here is about rounding to integers, and enums are ints by
> default, so really the numbers are equivalent to:
> Positivo =3D 0,
> Negativo =3D 1,
> Neutro =3D 1
> Which would make sense by what you see printed out.
> -----Original Message-----
> From: mono-list-admin@lists.ximian.com
> [mailto:mono-list-admin@lists.ximian.com] On Behalf Of gennady wexler
> Sent: Saturday, October 16, 2004 10:54 AM
> To: Iain McCoy; francis@aspl.es
> Cc: mono
> Subject: Re: [Mono-list] Enum problem
> On 10/16/04 4:33 AM, "Iain McCoy" <iain@mccoy.id.au> wrote:
>> On Sat, 2004-10-16 at 13:17 +0200, Francis Brosnan Bl=E1zquez wrote:
>>> Hi.
>>> Working with enumerations I've found an strange behaviour. If you
>>> compile the following source code and run it:
>>> --
>>> using System;
>>> public class EnumTest {
>>> public enum TipoCarga {
>>> Positivo =3D 1/3,
>>> Negativo =3D 1 + (1/3),
>>> Neutro   =3D 1,
>>> }
>> suspect what you're seeing is the compiler automatically coercing all
>> of your enum values to ints. This means that 1/3 =3D 0, so 1 + 1/3 =3D 0
>> and
> if 1/3 is 0 then how would 1 + 1/3 be 0 too?