Announcement

Collapse
No announcement yet.

Slack space need to line up PB and C++ UDT

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Slack space need to line up PB and C++ UDT

    wondering if anyone can shed light on the subject here.

    we have a call to a C++ dll in which we pass a UDT pointer from PB.

    If the PB UDT is nested, then the only way to get the C++ data to be extracted properly is to add 4 bytes of slack space in the UDT defined on the PB side.

    here is the C++ UDT. The U_STATUS is nested.

    Code:
    typedef struct  {
    
          UDT_STATUS  U_STATUS;
    
          int               p_GEOM_GRID;
    
          double            XA;
    
          double            YA;
    
          double            ZA;
    
          float       XV;
    
          float       YV;
    
          float       ZV;
    
          int               XW;
    
          int               YW;
    
          float       Q_SCALAR;
    
          UDT_ColorFraction U_Color_RGB;     
    
    } NODEDATA;
    In order for the PB code to deliver the pointer and access the data properly, the UDT must be defined like:

    Code:
       '  Supports GRID definition
       TYPE UDT_GRID
    
          n_Slack_04                                AS LONG                 '  c++ slack space 04 bytes
          U_STATUS                                  AS UDT_STATUS           '  GRID STATUS
    
          p_GEOM_GRID                               AS LONG                 '  Pointer from GRID to GEOM
    
          XA                                        AS DOUBLE               '  GRID Actual A Coordinate X (DOUBLE precision)
          YA                                        AS DOUBLE               '  GRID Actual A Coordinate Y (DOUBLE precision)
          ZA                                        AS DOUBLE               '  GRID Actual A Coordinate Z (DOUBLE precision)
    
          XV                                        AS SINGLE               '  GRID Viewed V Coordinate X (SINGLE precision)
          YV                                        AS SINGLE               '  GRID Viewed V Coordinate Y (SINGLE precision)
          ZV                                        AS SINGLE               '  GRID Viewed V Coordinate Z (SINGLE precision)
    
          XW                                        AS LONG                 '  GRID Window W Coordinate X Projected (LONG for screen coordinates)
          YW                                        AS LONG                 '  GRID Window W Coordinate Y Projected (LONG for screen coordinates)
    
          Q_Scalar                                  AS SINGLE               '  Scalar information for tagging
    
          n_Slack_08                                AS LONG                 '  c++ slack space 04 bytes
          U_Color_RGB                               AS UDT_ColorFraction    '  Color fraction for contour coloring COLC
    
       END TYPE
    any reasons or guidelines as to why this may be necessary?

    thanks, D

  • #2
    Some development products automatically (that is, your choice is their choice) use 2- or 4-byte alignment for structures, automatically inserting "slack bytes" where necessary. Or, the operating system may request a specific alignment (eg DLGTEMPLATE),

    You can have the your PB compiler do this,too - except your choice is YOUR choice - by specifying the desired aligment in the header of the TYPE definition....from the help file under TYPE/END TYPE ...

    Define a User-Defined Data Type (UDT), containing one or more member elements.

    Syntax
    Code:
     TYPE MyType [BYTE | WORD | DWORD | QWORD] [FILL]
    
      [MemberName [(subscripts)] AS] TypeName
    
      [MemberName [(subscripts)] AS TypeName]
    
      [...]
    
    END TYPE
    MCM
    Michael Mattias
    Tal Systems (retired)
    Port Washington WI USA
    [email protected]
    http://www.talsystems.com

    Comment


    • #3
      thanks for the note. I tested this on the PB side (DWORD FILL) but it still created the sizeof(UDT) = 80 bytes whereas C++ was 88 bytes. However, the C++ side dll may be treatable under similar methods and we are looking into that now. Stand by ...

      Comment


      • #4
        It's unusual to see padding before the first item in a structure. You don't provide enough information for me to be clear on what is going on but, it may be that C++ is expecting the entire structure to be aligned on some boundary. You might see if you can find out what alignment rules are in effect on the C++ side.

        Comment


        • #5
          It's unusual to see padding before the first item in a structure
          Yes, indeed. That's where a VPTR would go if the thing was really a C++ class that implements a single interface.
          Fred
          "fharris"+Chr$(64)+"evenlink"+Chr$(46)+"com"

          Comment

          Working...
          X