Task

Demonstrate how to specify the minimum size of a variable or a data type.




 
EnableExplicit
 
Structure AllTypes
  b.b
  a.a
  w.w
  u.u
  c.c    ; character type : 1 byte on x86, 2 bytes on x64
  l.l
  i.i    ; integer type : 4 bytes on x86, 8 bytes on x64
  q.q
  f.f
  d.d
  s.s    ; pointer to string on heap : pointer size same as integer
  z.s{2} ; fixed length string of 2 characters, stored inline
EndStructure
 
If OpenConsole()
  Define at.AllTypes  
  PrintN("Size of types in bytes (x64)")
  PrintN("")
  PrintN("byte      = " + SizeOf(at\b))
  PrintN("ascii     = " + SizeOf(at\a))
  PrintN("word      = " + SizeOf(at\w))
  PrintN("unicode   = " + SizeOf(at\u))
  PrintN("character = " + SizeOf(at\c))
  PrintN("long      = " + SizeOf(at\l))
  PrintN("integer   = " + SizeOf(at\i))
  PrintN("quod      = " + SizeOf(at\q))
  PrintN("float     = " + SizeOf(at\f))
  PrintN("double    = " + SizeOf(at\d))
  PrintN("string    = " + SizeOf(at\s))
  PrintN("string{2} = " + SizeOf(at\z))
  PrintN("---------------")
  PrintN("AllTypes  = " + SizeOf(at))
  PrintN("")
  PrintN("Press any key to close the console")
  Repeat: Delay(10) : Until Inkey() <> ""
  CloseConsole()
EndIf
 
 