Page 1 of 1

Nested structures

Posted: Thu Aug 14, 2008 7:43 pm
by Hroudtwolf
Hi Team,

My little wish is, to have the possibility of nested structures.
So, that we can put sub datasets in our structures.

Example C:

Code: Select all

typedef struct TEST {
   dword dwTest1;
   union {
      dword dwTest2;
      struct {
         word wTest3;
         word wTest4;
      }
   }

} TEST;
My recommendation for PB:

Code: Select all

Structure TEST
   lTest1.l
   StructureUnion
      lTest2.l
      StructureNested
         wTest3.w
         wTest4.w
      EndStructureNested
   EndStructureUnion
EndStructure
Best regards

Wolf

Posted: Thu Aug 14, 2008 8:12 pm
by tinman
How about SubStructure rather than StructureNested?

Would this only be used for anonymous structures (since we could easily define another external structure in the case where it is not anonymous)?

Posted: Thu Aug 14, 2008 8:41 pm
by Hroudtwolf
Sub datasets does only make sense for structureunion datasets.

Scenario:

You want to set a union dataset for "one long" and alternative for "2 word" for the same memoryblock.
So you can't set the 2 words into another structure for embedding it, because the new dataset datafield points to another memoryblock.

Sorry for my english. I hope another one can explain it better than myself.

Regards

Wolf

Posted: Thu Aug 14, 2008 9:36 pm
by Kaeru Gaman
that way it already works:

Code: Select all

Structure Nested
         wTest3.w
         wTest4.w
EndStructure

Structure TEST
   lTest1.l
   StructureUnion
      lTest2.l
      Test34.Nested
   EndStructureUnion
EndStructure 
> Sub datasets does only make sense for structureunion datasets.
could you pse post an example for a nested struct without a union?

Posted: Thu Aug 14, 2008 9:49 pm
by Hroudtwolf
@Kaeru

If I want to share the memory of lTest2 with to WORDs, it isn't the adequate way to point with Test34 to another memoryblock.

> Sub datasets does only make sense for structureunion datasets.
could you pse post an example for a nested struct without a union?
That wouldn't make sence in my opinion ^^

Please read an english documentation to nested structures in C.
The english in such docs should be better than mine.

Regards

Wolf

Posted: Thu Aug 14, 2008 9:56 pm
by Kaeru Gaman
If I want to share the memory of lTest2 with to WORDs, it isn't the adequate way to point with Test34 to another memoryblock.
you get this wrong.

a Structure is just a label how to adress the memory, not memory itself.

Define Carrier.Test in my example, and you can
use Carrier\Test34\wTest3 to access LoWord
and Carrier\Test34\wTest4 to access HiWord
of the Long in Carrier\lTest2


I often use

Code: Select all

Structure PointContainer
  StructureUnion
    L.l
    C.COORD
  EndStructureUnion
EndStructure
to Return both an x and y value from a Procedure though the returning Long.

Posted: Thu Aug 14, 2008 10:02 pm
by Hroudtwolf
Ok. Your right. My mistake.
I had a datasetpointer in my mind.

But, its a fact, that defining of subdatasets would be more easier with nested structures.

Regards

Wolf

Posted: Thu Aug 14, 2008 10:14 pm
by Kaeru Gaman
you mean you would not need two levels of \ to adress the nested element....?

would not be bad, but is also a matter of taste.
perhaps one wants to see how deep the nesting level is....

Posted: Sun Dec 14, 2008 6:07 pm
by Psychophanta
Needed for DirectDraw DDPIXELFORMAT Structure:

Code: Select all

Structure DDPIXELFORMAT
  dwSize.l
  dwFlags.l
  dwFourCC.l
  StructureUnion
    dwRGBBitCount.l
    dwYUVBitCount.l
    dwZBufferBitDepth.l
    dwAlphaBitDepth.l
    dwLuminanceBitCount.l
    dwBumpBitCount.l
    dwPrivateFormatBitCount.l
  EndStructureUnion
  StructureUnion
    dwRBitMask.l
    dwYBitMask.l
    dwStencilBitDepth.l
    dwLuminanceBitMask.l
    dwBumpDuBitMask.l
    dwOperations.l
  EndStructureUnion
  StructureUnion
    dwGBitMask.l
    dwUBitMask.l
    dwZBitMask.l
    dwBumpDvBitMask.l
    Structure MultiSampleCaps
      wFlipMSTypes.w
      wBltMSTypes.w
    EndStructure
  EndStructureUnion
  StructureUnion
    dwBBitMask.l
    dwVBitMask.l
    dwStencilBitMask.l
    dwBumpLuminanceBitMask.l
  EndStructureUnion
  StructureUnion
    dwRGBAlphaBitMask.l
    dwYUVAlphaBitMask.l
    dwLuminanceAlphaBitMask.l
    dwRGBZBitMask.l
    dwYUVZBitMask.l
  EndStructureUnion
EndStructure

Posted: Sun Dec 14, 2008 10:59 pm
by Rescator
@Psychophanta
Wouldn't this be valid?

Code: Select all

Structure MultiSampleCaps
  wFlipMSTypes.w
  wBltMSTypes.w
EndStructure
Structure DDPIXELFORMAT
  dwSize.l
  dwFlags.l
  dwFourCC.l
  StructureUnion
    dwRGBBitCount.l
    dwYUVBitCount.l
    dwZBufferBitDepth.l
    dwAlphaBitDepth.l
    dwLuminanceBitCount.l
    dwBumpBitCount.l
    dwPrivateFormatBitCount.l
  EndStructureUnion
  StructureUnion
    dwRBitMask.l
    dwYBitMask.l
    dwStencilBitDepth.l
    dwLuminanceBitMask.l
    dwBumpDuBitMask.l
    dwOperations.l
  EndStructureUnion
  StructureUnion
    dwGBitMask.l
    dwUBitMask.l
    dwZBitMask.l
    dwBumpDvBitMask.l
    MultiSampleCaps.MultiSampleCaps
  EndStructureUnion
  StructureUnion
    dwBBitMask.l
    dwVBitMask.l
    dwStencilBitMask.l
    dwBumpLuminanceBitMask.l
  EndStructureUnion
  StructureUnion
    dwRGBAlphaBitMask.l
    dwYUVAlphaBitMask.l
    dwLuminanceAlphaBitMask.l
    dwRGBZBitMask.l
    dwYUVZBitMask.l
  EndStructureUnion
EndStructure

Posted: Mon Dec 15, 2008 12:29 am
by Psychophanta
Well done Rescator, that's ok!
who said this request was necessary?
:P