I need to verify a variable is a certain type.
Is there a way to check the type of a variable in Ada?
I've tried looking at Ada attributes but didn't see anything.
I need to verify a variable is a certain type.
Is there a way to check the type of a variable in Ada?
I've tried looking at Ada attributes but didn't see anything.
Ada is a strongly typed language so there is really no need to have a function to return the variable's type, as there is in Python or Ruby (duck typed languages) because when you declare a variable you specify its type. The program already knows its type.
If a variable X is declared with type T'Class, then the type of the actual value can be T or any type derived from T. In that case, you can use X'Tag to get the tag of the value's actual type, which is the closest you can come to getting the actual type. Once you have a tag, you can do things like getting the type's name (there are functions for this in Ada.Tags), comparing it to the tag of some type to see if it's that type, etc. But Integer is not a tagged type, so you can't use 'Tag on it and there would be no use for it because it is a primitive type.