Enum's type

This topic contains 3 replies, has 2 voices, and was last updated by  TomToad 1 year, 9 months ago.

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #9357

    abakobo
    Participant

    -Are enums 32bit Uint or 32 bit signed Int? I can see an issue where it says ints can’t have negative literal.. (https://github.com/blitz-research/monkey2/issues/138). It looks like in C++ it can have negative members, wich can be a problem for importing external enums.

    -Are enums primitive types? (I suppose not)

    This is for documentation purpose.

    #9359

    TomToad
    Participant

    You could cheat a bit and use twos compliment

    [/crayon]

    is equivalent to C++

    [/crayon]

    To find the twos compliment of a signed Int, you can use Print Hex(UInt(-1)) in Monkey2

    #9444

    abakobo
    Participant

    Thanks for the trick!

    I still wonder if enums are primitive types (strings are so may be..) and if enums (will) have uint or int members. So I can make a correct description in the docs. (Looking at enum.monkey2 & values.monkey2 did not help me)

    #9445

    TomToad
    Participant

    An Enum will compile to an opaque enum class in the c++ source which uses a signed int for its base. For some reason, M2’s Enum will not accept negative values. I think this might be a parser bug as I can do this

    And it works as expected. (much easier to understand than the $FFFFFFFF hack I posted earlier)

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.