Nested Structure

Just starting out? Need help? Post your questions and find answers here.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Franco.

How deep can I go with nested structures :)
If I do:

Code: Select all

Structure ID3
  FileID.b[3]     ; 3 bytes
  IDMajor.b[1]    ; 1 byte
  IDMinor.b[1]    ; 1 byte - Revision
  FlagA.b[1]      ; 1 byte - Unsynchronisation
  FlagB.b[1]      ; 1 byte - Extended header 
  FlagC.b[1]      ; 1 byte - Experimental indicator
  FlagD.b[1]      ; 1 byte - Footer present 
  Size.l          ; 32 bit synchsafe integers
EndStructure
 
Structure ID3Info
  Header.ID3
  ExHeader.b[30] ; variable lenght OPTIONAL
  Frames.b[30]   ; variable lenght
  Padding.b[30]  ; variable lenght OPTIONAL
  Footer.b[10]   ; OPTIONAL
EndStructure
all seems to work fine.
I can get the FileID, IDMajor and IDMinor values:

Code: Select all

  ID$ = PeekS(@Mp3ID3\Header\FileID[0],3) ;PeekS works only with NULL terminated strings properly
  VersionMajor$ = Str(PeekB(@Mp3ID3\Header\IDMajor[0]))
  VersionMinor$ = Str(PeekB(@Mp3ID3\Header\IDMinor[0]))
  MessageRequester("ID",ID$,0) 
  MessageRequester("Version",VersionMajor$+"."+VersionMinor$,0) 
But if I do:

Code: Select all

Structure ID3Version
  IDMajor.b[1]    ; 1 byte
  IDMinor.b[1]    ; 1 byte - Revision
EndStructure
 
Structure ID3Flags
  FlagA.b[1]      ; 1 byte - Unsynchronisation
  FlagB.b[1]      ; 1 byte - Extended header 
  FlagC.b[1]      ; 1 byte - Experimental indicator
  FlagD.b[1]      ; 1 byte - Footer present 
EndStructure
 
Structure ID3Header
  FileID.b[3]         ; 3 bytes
  Version.ID3Version  ; 2 bytes
  Flags.ID3Flags      ; 4 bytes
  Size.l              ; 32 bit synchsafe integers
EndStructure
 
Structure ID3Info
  Header.ID3Header
  ExHeader.b[30] ; variable lenght OPTIONAL
  Frames.b[30]   ; variable lenght
  Padding.b[30]  ; variable lenght OPTIONAL
  Footer.b[10]   ; OPTIONAL
EndStructure
I get wrong results for IDMajor and IDMinor.

Code: Select all

  ID$ = PeekS(@Mp3ID3\Header\FileID[0],3) ;PeekS works only with NULL terminated strings properly
  VersionMajor$ = Str(PeekB(@Mp3ID3\Header\Version\IDMajor[0])
  VersionMinor$ = Str(PeekB(@Mp3ID3\Header\Version\IDMinor[0]))
  MessageRequester("ID",ID$,0) 
  MessageRequester("Version",VersionMajor$+"."+VersionMinor$,0) 
IDMajor contains the value of FileID etc.


Have a nice day...

Franco
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by tinman.
Originally posted by Franco
IDMajor.b[1] ; 1 byte
IDMinor.b[1] ; 1 byte - Revision
Does PB round up the size of structures so they are byte aligned? I would not have thought it would do it in the middle of a structure, but you never know :)

It may do it to arrays and not bytes. Have you tried not having an array of 1 byte?


--
It's not minimalist - I'm increasing efficiency by reducing input effort.
(Win98first ed. + SP1, PB3.40)
Post Reply