Page 1 of 1

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

Posted: Sun Feb 11, 2024 7:00 pm
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' ?

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

Posted: Sun Feb 11, 2024 7:19 pm
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.

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

Posted: Tue Feb 13, 2024 11:10 am
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

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

Posted: Tue Feb 13, 2024 4:23 pm
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

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

Posted: Tue Feb 13, 2024 5:06 pm
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.

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

Posted: Wed Feb 14, 2024 9:25 am
by Psychophanta
@juergenkulow
Good one.
This is one of the beloved features of PB 8)