Constant Number Type

I’m writing a bytecode virtual machine. I have a Select statement that selects a UInt8 variable called opcode. I want to compare this with various constant values to see which opcode I’m dealing with. In the IDE when you create a “Number” constant, what type is it exactly? I’m assuming it’s an Int64 or Int32 depending on the platform. Is there a way to create a UInt8 constant in a module or class?

Select Case opcode // This is a UInt8 Case kOP_RETURN // Handle return opcode Else // Unknown opcode End Select

I can’t use an Enumeration because they seem to be Integers and there is overhead converting them. I’m thinking the only option is to create properties of type UInt8 and just hope I don’t accidentally modify them by mistake (if they were constants then the compiler would prevent that and would probably optimise their storage too as they are known at compile time).

[quote=429906:@Garry Pettet]I’m writing a bytecode virtual machine. I have a Select statement that selects a UInt8 variable called opcode. I want to compare this with various constant values to see which opcode I’m dealing with. In the IDE when you create a “Number” constant, what type is it exactly? I’m assuming it’s an Int64 or Int32 depending on the platform. Is there a way to create a UInt8 constant in a module or class?

Select Case opcode // This is a UInt8 Case kOP_RETURN // Handle return opcode Else // Unknown opcode End Select

I can’t use an Enumeration because they seem to be Integers and there is overhead converting them. I’m thinking the only option is to create properties of type UInt8 and just hope I don’t accidentally modify them by mistake (if they were constants then the compiler would prevent that and would probably optimise their storage too as they are known at compile time).[/quote]

You may be able to use CType(TheNumberConst, UInt8) so it will convert it to UINt8

Trouble is that seems to be an unnecessary method call. The whole point of using a constant is that the compiler can optimise for it.

Numeric constants don’t have a “type”… 123 could be used as an Integer, Single or Double… it would depend on the context where it was USED, not where it was created. The Xojo compiler takes the constants defined value and replaces it in all appropriate code locations prior to the compile step.

So if you entered this code

CONST xyz=123
DIM x as Integer
x=xyz

where would get compiled is

DIM x as integer
x=123

no… the whole point is for Developer convience

in code you can type constants

Const foo As UInt8 = 45

The constant editor doest let you type them this way

But I would not worry about it since you can safely compare a Uint8 to a Integer etc