Type detection: Difference between revisions

Content added Content deleted
(Type detection in FreeBASIC)
Line 851: Line 851:


end program type_detection_demo</pre>
end program type_detection_demo</pre>

=={{header|FreeBASIC}}==
<syntaxhighlight lang="vbnet">'Rosetta Code problem: https://rosettacode.org/wiki/Type_detection
'by Jjuanhdez, 02/2023

#macro typeDetector(arg)
#if TypeOf(foo) = TypeOf(Byte)
Print arg; " -> It's a Byte!"
#elseif TypeOf(foo) = TypeOf(Short)
Print arg; " -> It's a Short!"
#elseif TypeOf(foo) = TypeOf(Integer)
Print arg; " -> It's a Integer!"
#elseif TypeOf(foo) = TypeOf(LongInt)
Print arg; " -> It's a LongInt!"
#elseif TypeOf(foo) = TypeOf(UByte)
Print arg; " -> It's a UByte!"
#elseif TypeOf(foo) = TypeOf(UShort)
Print arg; " -> It's a UShort!"
#elseif TypeOf(foo) = TypeOf(UInteger)
Print arg; " -> It's a UInteger!"
#elseif TypeOf(foo) = TypeOf(ULongInt)
Print arg; " -> It's a ULongInt!"
#elseif TypeOf(foo) = TypeOf(Single)
Print arg; " -> It's a Single!"
#elseif TypeOf(foo) = TypeOf(Double)
Print arg; " -> It's a Double!"
#elseif TypeOf(foo) = TypeOf(integer ptr)
Print arg; " -> It's a Integer ptr!"
#elseif TypeOf(foo) = TypeOf(byte ptr)
Print arg; " -> It's a Byte ptr!"
#elseif TypeOf(foo) = TypeOf(String)
Print arg; " -> It's a String!"
#endif
#endmacro

'Var declares a variable whose type is implied from the initializer expression.
'Var foo = -6728 '' implicit integer
'Var foo = 1.985766472453666 '' implicit double
Var foo = "Rosetta Code" '' var-len string

typeDetector (foo)
Sleep</syntaxhighlight>


=={{header|Go}}==
=={{header|Go}}==