- In many languages, none integer variable is implicitly convertible to a ENUM instance (and reciprocally), this one being strongly typed (declaration equivalent to the ENUM qualified as EXPLICIT with FreeBASIC), and an explicit CAST is required for such a conversion.
- But FreeBASIC accepts it (even if the numeric value does not match any ENUM symbol defined). This is just one of the many lacks of FreeBASIC on the normal ENUM features.
Therefore, there is no many interest to declare a true ENUM instance (which is sized as an INTEGER), but otherwise any pre-built integer variable ([U]BYTE, [U]SHORT, [U]LONG...) can be declared instead:
Code: Select all
ENUM My_Options Explicit
Dim As My_Options opt_a ' Enum instance
opt_a = My_Options.OPTION_3
Print opt_a, Sizeof(opt_a)
Dim As Byte opt_b ' Byte instance
opt_b = My_Options.OPTION_3
Print opt_b, Sizeof(opt_b)
If we don't use the EXPLICIT qualifier (namespace prefix not imposed), I don't see much point in using an ENUM structure compared to a simple discrete list of constants (except the auto-increment of values).