Issue with Sizeof() and may be other...

Just starting out? Need help? Post your questions and find answers here.
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Issue with Sizeof() and may be other...

Post by Psychophanta »

Next tip shows it , because it is easy to see the failure in the returned values:

Code: Select all

character.q
Debug SizeOf(character); displays 2

character2.q
Debug SizeOf(character2); displays 8

ascii.f
Debug SizeOf(ascii); displays 1

ascii2.f
Debug SizeOf(ascii2); displays 4
Is it normal? What if wanted the size of a variable named for example 'ascii.f' ?
http://www.zeitgeistmovie.com

while (world==business) world+=mafia;
User avatar
STARGÅTE
Addict
Addict
Posts: 2260
Joined: Thu Jan 10, 2008 1:30 pm
Location: Germany, Glienicke
Contact:

Re: Issue with Sizeof() and may be other...

Post by STARGÅTE »

https://www.purebasic.com/documentation ... tions.html
Syntax
Size = SizeOf(Type)

Description
SizeOf can be used to find the size of any complex Structure, built-in type (word, float, etc.), Interface or even ReferenceLink "variables" "variables" (Structures with same name as variable take precedence). This can be useful in many areas such as calculating memory requirements for operations, using API commands, etc.
So, yes, it es normal.
PB 6.01 ― Win 10, 21H2 ― Ryzen 9 3900X, 32 GB ― NVIDIA GeForce RTX 3080 ― Vivaldi 6.0 ― www.unionbytes.de
Lizard - Script language for symbolic calculations and moreTypeface - Sprite-based font include/module
juergenkulow
Enthusiast
Enthusiast
Posts: 581
Joined: Wed Sep 25, 2019 10:18 am

Re: Issue with Sizeof() and may be other...

Post by juergenkulow »

Code: Select all

;PB is very flexible. 
#Vector4=4711
Define Vector4
Dim Vector4(42)
;NewList Vector4()
;NewMap Vector4()
;Procedure Vector4(): EndProcedure
DeclareModule Vector4 : EndDeclareModule : Module Vector4 : EndModule
Vector4:
Enumeration Vector4 : #One : #Two : #Three : EndEnumeration
;Prototype Vector4()
;Interface Vector4 : EndInterface


CompilerIf Defined(Vector4,#PB_Constant)
  Debug "Vector4 is a Constant."
CompilerEndIf
CompilerIf Defined(Vector4,#PB_Variable)
  Debug "Vector4 is a Variable."
CompilerEndIf  
CompilerIf Defined(Vector4,#PB_Array)
  Debug "Vector4 is a Array."
CompilerEndIf  
CompilerIf Defined(Vector4,#PB_List)
  Debug "Vector4 is a List."
CompilerEndIf  
CompilerIf Defined(Vector4,#PB_Map)
  Debug "Vector4 is a Map."
CompilerEndIf  
CompilerIf Defined(Vector4,#PB_Structure)
  Debug "Vector4 is a Structure."
CompilerEndIf  
CompilerIf Defined(Vector4,#PB_Procedure)
  Debug "Vector4 is a Procedure."
CompilerEndIf  
CompilerIf Defined(Vector4,#PB_Module)
  Debug "Vector4 is a Module."
CompilerEndIf  
CompilerIf Defined(Vector4,#PB_Label)
  Debug "Vector4 is a Label."
CompilerEndIf 
CompilerIf Defined(Vector4,#PB_Enumeration)
  Debug "Vector4 is a Enumeration."
CompilerEndIf 
CompilerIf Defined(Vector4,#PB_Prototype)
  Debug "Vector4 is a Prototype."
CompilerEndIf 
CompilerIf Defined(Vector4,#PB_Interface)
  Debug "Vector4 is a Interface."
CompilerEndIf 
Debug "SizeOf(Vector4):"+Str(SizeOf(Vector4))
Debug "TypeOf(Vector4):"+Str(TypeOf(Vector4)) +" "+Str(#PB_Structure)
; Structure Vector4
;   x.f
;   y.f
;   z.f
;   w.f
; EndStructure

; Vector4 is a Constant.
; Vector4 is a Variable.
; Vector4 is a Array.
; Vector4 is a Structure.
; Vector4 is a Module.
; Vector4 is a Label.
; Vector4 is a Enumeration.
; SizeOf(Vector4):16
; TypeOf(Vector4):7 7
Olli
Addict
Addict
Posts: 1266
Joined: Wed May 27, 2020 12:26 pm

Re: Issue with Sizeof() and may be other...

Post by Olli »

To complete the answers of Stargate and juergenkulow, "character" is a pre-defined keyword.

Code: Select all

Define character.Q ; here, an error should occur.
Debug SizeOf(CHARACTER); displays 2

Define character2.q
Debug SizeOf(character2); displays 8
juergenkulow
Enthusiast
Enthusiast
Posts: 581
Joined: Wed Sep 25, 2019 10:18 am

Re: Issue with Sizeof() and may be other...

Post by juergenkulow »

Code: Select all

Structure Character
  c.c
EndStructure
"Character" is a pre-defined structure. You can find it under Tools Structure Viewer C.
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Re: Issue with Sizeof() and may be other...

Post by Psychophanta »

@juergenkulow
Good one.
This is one of the beloved features of PB 8)
http://www.zeitgeistmovie.com

while (world==business) world+=mafia;
Post Reply