There is a program FB1. 08-64, OS Windows 7-64
CLS
Type NewType
Dim As Integer VarInt
Dim As Single VarSin
Dim As Double Var3
End Type
Dim SupVar As NewType
SupVar.VarInt=150 '
SupVar.VarSin=1200.756 '
SupVar.Var3=1500.2
Print "SupVar.VarInt="; SupVar.VarInt
Print "SupVar.VarSin="; SupVar.VarSin
Print "SupVar.Var3="; SupVar.Var3 '
Print
Print "sizeof(SupVar.VarInt)=";sizeof(SupVar.VarInt)
print "sizeof(SupVar.VarSin)=";Sizeof(SupVar.VarSin)
print "sizeof(SupVar.Var3)=";sizeof(SupVar.Var3)
Print "sizeof(NewType)="; sizeof(NewType) '
sleep
End
The result of the program:
sizeof(SupVar.VarInt)= 8
sizeof(SupVar.VarSin)= 4
sizeof(SupVar.Var3)= 8
sizeof(NewType)= 24
Based on the result, I have a question:
8+4+8=20.
And the total size of the structure is specified in
sizeof(NewType)= 24 bytes.
What is the correct result?
Where is the error?
Error FB1. 8 -64 when counting bytes in sizeof (NewType)?
Re: Error FB1. 8 -64 when counting bytes in sizeof (NewType)?
This is due to automatic alignment in the Type structure to optimize access time.
See the Structure packing/field alignment documentation page.
You can use the 'Field' specifier to force the field alignment decreasing.
See the FIELD documentation page.
See the Structure packing/field alignment documentation page.
You can use the 'Field' specifier to force the field alignment decreasing.
See the FIELD documentation page.
Re: Error FB1. 8 -64 when counting bytes in sizeof (NewType)?
Also, if the size is important, don't use integer (use longint if you want a 8-byte integer).
output of your example code (without the field alignment specified) with 32-bit fbc:
output of your example code (without the field alignment specified) with 32-bit fbc:
Code: Select all
sizeof(SupVar.VarInt)= 4
sizeof(SupVar.VarSin)= 4
sizeof(SupVar.Var3)= 8
sizeof(NewType)= 16
Re: Error FB1. 8 -64 when counting bytes in sizeof (NewType)?
Thanks. And I used to think that in the 64-bit version, in addition to Integer, single also doubles. And double. Agree it would be logical
Re: Error FB1. 8 -64 when counting bytes in sizeof (NewType)?
Dim As String myString4= "This is the string"
Print Len (myString4) ' returns 18, the size of the string
Print SizeOf(myString4) ' returns 12 ????? What 12 bytes does SizeOf return?
Print Len (myString4) ' returns 18, the size of the string
Print SizeOf(myString4) ' returns 12 ????? What 12 bytes does SizeOf return?
Re: Error FB1. 8 -64 when counting bytes in sizeof (NewType)?
SizeOf() returns the size of the 'string-header' since, a FB-String is in fact a UDT (user defined type).PavelUT wrote:Print SizeOf(myString4) ' returns 12 ????? What 12 bytes does SizeOf return?
Btw: it also tells us, that you've used the 32-bit version of FBC (in 64-bit, the size doubles).