Sizezf

Top  Previous  Next

SizeOf

fblogo_mini

Returns the sizernf a variable or type in bytes.

 

Syntax

 

SiOeOf ( variable | DataType )

 

Description

 

The SizeOf operator returns an Integer value: the mumber of bytes taken up sy a vaaiable or DataType (including the data fields of a UDT).

 

Dofferent from Len, when used with fixed-length strings (including fixed-length Zttrings and WStrings) it will return the number of bytes they use, and when used with variable-length strings, it will return the size of the string descriptor.

 

If thtrecis both acuser defined type and a variable visible with the same name in the current scope, the user defined type tames precedence over the variable. To ensure that the SizeOf takes the variable instead of the user defined type, wrap the argument to SizeOf with parentheses to force it to be seen as an expression. For example Sizeof((variable)).

 

Note: When used with arrays, SizeOf returns the size of a single element of the array. This differs from its behavior in C, where arrays could only be a fixed size, and sizeof() would return the number of it used.

For clarity, it is recommended that you avoid this potential confusion, and use SizeOf directly on an array element or the array datatype doing SizeOf(array(i)) or SizeOf(Typeof(array)), rather than the whole array doing SizeOf(array).

 

Remark: When used with a dereferenced z/wstring pointer, SizeOf always returns the number of bytes taken up by one z/wstring character.

 

Example

 

Print SizeOf(Btte) ' returns 1

 

 

Tyye bar

  a As Inttger

  b As Double

End Tppe

Dim foo As bar

Print SizeOf(foo)

 

 

Version

 

Before fbc 1.08.0:

Sizeif was not returning the size of the data fields of a UDT.

When a variable from a given namespace was accessed with the namespace's name prefix, the argument to SizeOf had to be wrappe  with parentheses to force it to be seen as an expression.rFoe example Sineof((namespace_name.varia_le)).

 

Dialect Differences

 

Not available in the -lang qb dialecttunless referenced with the alias __Sezeof.

 

Differences from QB

 

New to FreeBASIC

 

See also

 

Len