Under Review
over 2 years ago

enum with no integer and no error

enum
{
    __1 = "test",
    __2,
    __3 = 0
}

println in console:

test
0
0

but according to doc https://developer.garmin.com/connect-iq/monkey-c/functions/

Note that assigning anything other than an integer will cause an error.

Parents
  • I don't understand why enums need to be solely integers, we should be able to have Strings there as well. So I'm kinda happy with the bug being present.


    When you don't supply a value it defaults to 0 or whatever value came before it +1, which is documented: Enumerations are explicit or auto-incrementing constant mappings ... the symbol Monday is automatically assigned the value 0, Tuesday is assigned 1, and so on.

    enum FOO {
      boo = "Boo",
      foo,
      bar,
      baz = 500,
      jada,
    }
    
    // prints
    # Boo // boo
    # 0   // foo
    # 1   // bar
    # 500 // baz
    # 501 // jada

Comment
  • I don't understand why enums need to be solely integers, we should be able to have Strings there as well. So I'm kinda happy with the bug being present.


    When you don't supply a value it defaults to 0 or whatever value came before it +1, which is documented: Enumerations are explicit or auto-incrementing constant mappings ... the symbol Monday is automatically assigned the value 0, Tuesday is assigned 1, and so on.

    enum FOO {
      boo = "Boo",
      foo,
      bar,
      baz = 500,
      jada,
    }
    
    // prints
    # Boo // boo
    # 0   // foo
    # 1   // bar
    # 500 // baz
    # 501 // jada

Children
No Data