Guys, is there a function to display type of variables like:
i.d = 2.5
Debug isDouble(i)
typeof
Re: typeof
no you would need to make use of opaque types
for example something like this
for example something like this
Code: Select all
Structure opaque
type.i
StructureUnion
a.a
b.b
u.u
c.c
w.w
l.l
i.i
ptr.i
f.f
d.d
q.q
EndStructureUnion
s.s
EndStructure
Define var.opaque
var\type = #PB_Double
var\d = #PI
If var\type = #PB_Double
Debug StrD(var\d,14)
EndIf
Windows 11, Manjaro, Raspberry Pi OS


-
- Always Here
- Posts: 6426
- Joined: Fri Oct 23, 2009 2:33 am
- Location: Wales, UK
- Contact:
Re: typeof
....just prefix the name of your vars and you'll always know what they are:
iMyInt.i
dMyDouble.d
sMyString.s
I differentiate between Global Vars and Local vars by giving the Global a 'g' prefix:
igMyInt.i
dgMyDouble.d
sgMyString.s
etc
iMyInt.i
dMyDouble.d
sMyString.s
I differentiate between Global Vars and Local vars by giving the Global a 'g' prefix:
igMyInt.i
dgMyDouble.d
sgMyString.s
etc
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
If it sounds simple, you have not grasped the complexity.
-
- Addict
- Posts: 2344
- Joined: Mon Jun 02, 2003 9:16 am
- Location: Germany
- Contact:
Re: typeof
You'd need reflection or at least type introspection for this. I myself thought about a precompiler for purebasic to do this, but I have no time. Maybe someone who did one of those OOP precompilers could do it.
bye,
Daniel
Daniel
Re: typeof
Reflection is also used to get functions and types from outside (of a DLL/EXE).DarkDragon wrote:You'd need reflection for this. I myself thought about a precompiler for purebasic to do this, but I have no time. Maybe someone who did one of those OOP precompilers could do it.
The PB compiler knows the variable type already, so typeof(variable) could be easily added and
it could be useful together with macros. Maybe a new feature request?
Code: Select all
Macro ToString(_value_)
CompilerSelect TypeOf(_value_)
CompilerCase #PB_TYPE_FLOAT
( StrF(_value_) )
CompilerCase #PB_TYPE_DOUBLE
( StrD(_value_) )
CompilerDefault
( Str( _value_ ) )
CompilerEndSelect
EndMacro
Re: typeof
yes I think a compiler directive could be useful, but if you want to know what a type is at runtime
you either need to use a runtime component to allocate your variables on the heap which also tracks the types
or use opaque types, if that's a fair use of the term.
you either need to use a runtime component to allocate your variables on the heap which also tracks the types
or use opaque types, if that's a fair use of the term.
Windows 11, Manjaro, Raspberry Pi OS

