[Implemented] expand SizeOf() and add TypeOf()

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6166
Joined: Sat May 17, 2003 11:31 am
Contact:

[Implemented] expand SizeOf() and add TypeOf()

Post by blueznl »

* edit: see my post a little lower :-)

r = VarType ( <varname> )
r = VarType ( <varname\structfield> )
r = VarSize ( <varname> )
r = VarSize ( <varname\structfield> )

VarType() returns #PB_VarType_Byte for bytes, #PB_VarType_Word for words, etc. etc.

VarSize() returns how many bytes the variable or struct field takes up in memory, a string would be 4, a pointer 4, a static array b[100] would return 100

this would make intelligent struct manipulation possible, for example it would become possible to write a routine that copies a struct, as it can detect what type a struct field is, and take appropriate action
Last edited by blueznl on Mon May 10, 2004 10:36 pm, edited 2 times in total.
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide right here... )
User avatar
tinman
PureBasic Expert
PureBasic Expert
Posts: 1102
Joined: Sat Apr 26, 2003 4:56 pm
Location: Level 5 of Robot Hell
Contact:

Post by tinman »

You can use sizeof (<varname>) now.
If you paint your butt blue and glue the hole shut you just themed your ass but lost the functionality.
(WinXPhSP3 PB5.20b14)
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6166
Joined: Sat May 17, 2003 11:31 am
Contact:

Post by blueznl »

will that work on bytearrays? nope, as it will not even work on fields of a struct...

Code: Select all

Structure t
  b.b
  c.b[100]
EndStructure

x.t
Debug SizeOf(x\c)
Debug SizeOf(x)
Debug SizeOf(x\b)
and SizeOf(t\b) will not even be allowed by the compiler :-)

ah... thanks people on the irc :-)

may i change my request, i want SizeOf() to report the size of a field of a struct, such as:

Debug SizeOf(t\b) would then report 1

and a new command called TypeOf()
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide right here... )
Dare2
Moderator
Moderator
Posts: 3321
Joined: Sat Dec 27, 2003 3:55 am
Location: Great Southern Land

Post by Dare2 »

Yes = TypeOf = High on my wishlist - makes dynamic coding easier.

It runs just a little below double precision floats in desirability. :)
Post Reply