Link to home
Start Free TrialLog in
Avatar of RunePerstrup
RunePerstrup

asked on

Type conversion problem in enum declaration

I have a type conversion problem with some C# examples from the Fmod Ex sound system for C#. The engine fails, and - for some reason - the fmod team don't seem to be willing to correct their bugs. However, it should be relatively easy to correct... if i only knew why it fails...

The code has a number of declarations. They all work nicely apart from the last one that fails with the error "Cannot implicitly convert type uint to int". This seems illogical since the declaration is preceded by "(unit)".
I am using Visual studio 2005.

    public enum DEBUGLEVEL
    {
        LEVEL_NONE           = 0x00000000,
        LEVEL_LOG            = 0x00000001,

(etc... this is followed by a number of declarations. They all work fine apart from this last one that fails:)

        ALL                  = (uint)0xFFFFFFFF
    }

How can i solve this problem?
ASKER CERTIFIED SOLUTION
Avatar of vo1d
vo1d
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
1. enums emit enumerations with the underlying type Int32, therefore if you use casting it should be ALL = (int)0xFFFFFFFF
2. 0xFFFFFFFF will cause an owerflow if converted from uint to int (error CS0221), if you want you could use unchecked syntax to dont check if there will be an overflow, anyway..you well get that overflow.

change your enum like this to convert it from int32 to long
public enum DEBUGLEVEL:long
{
...
}

oh, yes, uint will be better (sorry, I didn't see your answer)
if he uses uint for his enum, everything is fine. there is no need for negative values.
oh, just gave my comment during your last post.
so, dont care about it, you have seen the uint thing tho ;)
Avatar of RunePerstrup
RunePerstrup

ASKER

Sorry for my late response, I have been away from my computer. I appreciate you response and will try to solve the problem from this point.

Please have a little patience before i give my points.

Rune
That did it, thanks vo1d

Rune