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.

  • Even with the highest level, it doesn't emit warnings of any kind.

    Oh I thought if you actually tried to use the values in a type-safe way, there'd be some kind of type error. But it was a while ago when I tried it out and tbh I don't even care that much about this problem. My bad tho.

  • I mean to me the real problem is reality doesn't match Garmin documentation, as per usual.

    Then it's up to us to guess what the true intent was (if we even bother to care.)

    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.

    They don't have to be, unless you're writing C. But seems like Garmin thought they should be. ¯\_(ツ)_/¯

  • Possibly, if you look at the beginning of the wiki page you'll see:

    In computer programming, an enumerated type (also called enumerationenum, or factor in the R programming language, and a categorical variable in statistics) is a data type consisting of a set of named values called elementsmembersenumeral, or enumerators of the type

    If you look at enumeration on wikipedia, you'll see:

    An enumeration is a complete, ordered listing of all the items in a collection. The term is commonly used in mathematics and computer science to refer to a listing of all of the elements of a set.

    Elements in a set are not integers by definition. It can be anything in that set.

    In any case, I don't think strings should be dropped from being used in enums, but rather, the documentation should be updated. 

  • Conceptually, an enumerated type is similar to a list of nominals (numeric codes), since each possible value of the type is assigned a distinctive natural number.

    So some languages have left from concept. :)

  • 1. Or both ;)
    2. enums on string: person, company, government

    en.wikipedia.org/.../Enumerated_type

    When enums are used in XML it is often a string and not just a number/integer. An example in use by Dutch gov:

    	<simpleType name="FunctieVrijBerichtElement">
    		<restriction base="string">
    			<enumeration value="antwoord"/>
    			<enumeration value="entiteit"/>
    			<enumeration value="selectie"/>
    			<enumeration value="update"/>
    			<enumeration value="zaakinfo"/>
    		</restriction>
    	</simpleType>