Archive

Posts Tagged ‘Pascal’

Converting C structs and unions to Pascal (or Object Pascal / Delphi) records

I’ve been recently adding support for QuickTime TimeCode tracks to the JEDI QuickTime library’s “qt_QuickTimeComponents.pas” file and I thought I should share a quick reminder on how we convert C structs (records) and unions (sets) into Pascal (Delphi / Object Pascal in this case) records:

Structs:

struct TimeCodeCounter {
long counter;
};
typedef struct TimeCodeCounter TimeCodeCounter;

type
long=integer; //in JEDI QuickTime I opted to create aliases for common C types to avoid converting them to Pascal equivalents everywhere
TimeCodeCounter = record
counter:long;
end;

Unions:

union TimeCodeRecord {
TimeCodeTime t;
TimeCodeCounter c;
};

type TimeCodeRecord = record
case integer of //C’s union
0: (t: TimeCodeTime);
1: (c: TimeCodeCounter);
end;

Do note that you should use “packed record” in Pascal if the C code uses respective #pragma command to define 0-packing gap between record fields (the default for C and Pascal compilers is to do field alignment to word [16-bit] boundaries for optimization purposes)

Categories: Posts Tags: , , , , ,
%d bloggers like this: