Page 1 of 1

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

Posted: Mon May 10, 2004 5:13 pm
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

Posted: Mon May 10, 2004 9:43 pm
by tinman
You can use sizeof (<varname>) now.

Posted: Mon May 10, 2004 10:31 pm
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()

Posted: Tue May 11, 2004 2:11 am
by Dare2
Yes = TypeOf = High on my wishlist - makes dynamic coding easier.

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