While it would be nice, and other languages have that, it is far away. PB doesn't even have type checking for structure parameters, which you declare and pass as pointers and you can pass just any number, not even just integers then, and structures are already types, kind of. Compile-time checking for enums isn't just a check at the call, but involves the whole type system. What if you want to store your current action in a variable. It couldn't be just an integer variable, but would have to be of the enum type. With this comes other questions like arithmetics/operators, for example increasing that variable to get the next action / enum value. Type conversions etc..
If you need unique values, i would use addresses, for example of variables in a module:
- no compile time checks
- using an empty structure to have a type for parameter declaration
- using duplicates of the action name (variables) and convert to address inside module, so you don't have to use Action::@Copy
Code: Select all
EnableExplicit
; ----------------------------------------
; Action Types
DeclareModule Action
Structure ActionType
EndStructure
Define Idle
Define Copy
EndDeclareModule
Module Action
Define _Idle
Define _Copy
Idle = @_Idle
Copy = @_Copy
EndModule
; ----------------------------------------
Procedure act(*a.Action::ActionType)
Select *a
Case Action::Idle
Debug "idle"
Case Action::Copy
Debug "copy"
Default
Debug "unkown"
EndSelect
EndProcedure
act(Action::Idle)
act(Action::Copy)
Define number.b
act(@number)
Define myAction = Action::Copy
act(myAction)
This isn't really different from just using enums directly in terms of types, but the values are less likely to come from another context like other/wrong enums or uninitialized variable etc. so it's less likely you pass a wrong value that works by accident.