Data Structure Functions

Unlike the programming language C, Benchmark Description Language (BDL) does not support structured data types. Instead, BDL uses a series of type-dependent Get and Set functions to access data in external C data structures.

The following example illustrates a C data structure:

typedef struct Struct1 {  
  char myChar;       // size: 1 byte pos: 1  
  short myShort;     // size: 2 bytes pos: 2  
  long myLong;       // size: 4 bytes pos: 4  
  double myDouble;   // size: 8 bytes pos: 8  
  float myFloat;     // size: 4 bytes pos: 16  
  ushort myUShort;   // size: 2 bytes pos: 20  
  char myString[10]; // size: 10 bytes pos: 22  
  uchar myUChar;     // size: 1 byte pos: 32
// size of Struct1: 32 bytes
Note: This data structure is used in all examples accompanying the help for the Get and Set functions that access C data structures.

To access the elements of a C data structure, you must first declare a corresponding BDL string as follows in order to map the C structure into BDL:

  SIZE_STRUCT := 32;
  myBDLstring: string(SIZE_STRUCT);

This allocates the same amount of storage space for the BDL string as for the original C data structure.

You can use BDL strings as actual parameters to external C functions where the external function expects a pointer to a data structure as parameter:

// C code
extern void ExtCFunc1(Struct1 *pStruct)
    pStruct->myChar = 1;  
    pStruct->myUChar = 10;

// BDL function prototype
DLL "ExtFunc.DLL"
  "ExtCFunc1" function ExtCFunc(inout string);
// BDL usage
  SetChar(myBDLstring, 1, ord('A'));  

In the examples, the starting positions for the function examples correspond to the respective data types in Struct1. The starting positions in the BDL string are given at the right next to “pos:” in the C data structure above.