FutureBasic Logo

<<    Index    >> FutureBasic 5

typeof   function



Syntax:
dataType = typeof({variable|typeName})

Description:
When FutureBasic compiles your program, it associates a unique integer with each data type that your program uses. The typeof function returns the integer that's associated with the specified type.
typeName should be the name of a type that was previously defined in a begin record statement or a #define statement; or the name of one of FutureBasic's built-in types (such as int, long, etc.).
variable can the name of any variable. In this case, typeof returns the type ID number associated with the variable's type. Note that if the variable was not previously declared in a dim statement, and has no type-identifier suffix, typeof will assume that the variable's type is the default type (which is int unless a def<type> statement applies).

Example:
This program uses typeof to determine what kind of data a pointer points to.
local fn DoSomething(@varAddr&, varType)
   print "The data you passed was: ";
   select varType
case typeof(int)
print peek word(varAddr&)
case typeof(long)
print peek long(varAddr&)
case typeof(Str255)
print pstr$(varAddr&)
case else
print "Unknown"
   end select
end fn

myInt% = 1623
fn DoSomething(myInt%, typeof(myInt%))
myLong& = 426193
fn DoSomething(myLong&, typeof(myLong&))
myPascalString = "Hello"
fn DoSomething(myPascalString, typeof(myPascalString))
end

program output:
The data you passed was: 1623
The data you passed was: 426193
The data you passed was: Hello


Note:
The integer values returned by typeof are determined dynamically at compile time. You should not count on typeof(someType) to return the same value every time your program is compiled.

See Also:
sizeof; Appendix C - Data Types and Data Representation