TypeOf or similar function

Just starting out? Need help? Post your questions and find answers here.
somic
User
User
Posts: 66
Joined: Sun Jun 29, 2008 9:11 am
Location: Italy
Contact:

TypeOf or similar function

Post by somic »

Hi,
ask for help.

Does someone know how it is possible to determine the type of variable at runtime:

es. something like

Code: Select all

*addr = @dbl
if typeof(*addr) = #pb_double
...
elseif typeof(*addr) = #pb_fixedstring
...
typeof(*addr) = #pb_array
...
Thank you for any advice
Rgds,
Somic
----------------------------------------------------------------------------
Semel in anno licet insanire (Seneca)
email: somic@libero.it, website: http://www.semelinanno.com
SFSxOI
Addict
Addict
Posts: 2970
Joined: Sat Dec 31, 2005 5:24 pm
Location: Where ya would never look.....

Re: TypeOf or similar function

Post by SFSxOI »

This maybe some info? http://www.purebasic.fr/english/viewtop ... lit=TypeOf a compiler directive? Don't know if it ever got added as Fred seems to indicate in that thread.
The advantage of a 64 bit operating system over a 32 bit operating system comes down to only being twice the headache.
eesau
Enthusiast
Enthusiast
Posts: 589
Joined: Fri Apr 27, 2007 12:38 pm
Location: Finland

Re: TypeOf or similar function

Post by eesau »

It wouldn't be possible to use TypeOf() on a pointer, as it is just a pointer, and could point to anything. TypeOf for variables would be possible though.
somic
User
User
Posts: 66
Joined: Sun Jun 29, 2008 9:11 am
Location: Italy
Contact:

Re: TypeOf or similar function

Post by somic »

@SFSxOI
I knew about that thread but also not able to find the implementation.

@eesau
I understand your point, but SizeOf(*addr) gives correct size of anything pointed by *addr.

I guess that, somewhere in the memory there should be stored the info.
----------------------------------------------------------------------------
Semel in anno licet insanire (Seneca)
email: somic@libero.it, website: http://www.semelinanno.com
User avatar
Demivec
Addict
Addict
Posts: 4260
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Re: TypeOf or similar function

Post by Demivec »

somic wrote:@eesau
I understand your point, but SizeOf(*addr) gives correct size of anything pointed by *addr.

I guess that, somewhere in the memory there should be stored the info.
If you use SizeOf(*addr) it will always be equal to the size of an Integer. Pointers are Integer variables that reference an address. Here is example code to illustrate:

Code: Select all

Define *addr.Quad,*addr2.Byte

Debug SizeOf(*addr) ;displays 4 on x86 32-bit
Debug SizeOf(*addr2) ;displays 4 on x86 32-bit
I don't think the size is stored anywhere in memory. SizeOf() is a compiler function which means that it doesn't use runtime values. That means the values wouldn't be stored in memory during runtime.
Post Reply