MAINSAIL Language Manual, Appendix L

previous   next   top   contents   index   framed top   this page unframed


L. Predefined Data Type Macros

To facilitate data sharing with C, MAINSAIL predefines some macros relating to C data types.

The data type sizes $shortSize, $intSize, and $longSize are chosen based on the target system:

Macro Identifier Meaning
$shortSize size of C short (typically 2)
$intSize size of C int (typically 4)
$longSize size of C long (typically 4)

The following predefined bracketed text macros can be used to represent C data types in MAINSAIL CLASS fields:

Macro Identifier Definition C Data Type
$CHAR INTEGER(1) unsigned char
$SIGNEDCHAR INTEGER(-1) signed char
$CHARBITS BITS(1) unsigned char
$CSHORT LONG INTEGER(- $shortSize) signed short
$CSHORTBITS LONG BITS($shortSize) unsigned short
$CINT LONG INTEGER(- $intSize) signed int
$CINTBITS LONG BITS($intSize) unsigned int
$CLONG LONG INTEGER(- $longSize) signed long
$CLONGBITS LONG BITS($longSize) unsigned long
$CFLOAT REAL float
$CDOUBLE LONG REAL double
$CSTRUCT(c) $RECORD(c) struct c
$CADRLONG LONG INTEGER(- number of bytes in an address) signed integer the same size as a C pointer
$CADRLONGBITS LONG BITS(- number of bytes in an address) unsigned integer the same size as a C pointer

The macros $CADRLONG and $CADRLONGBITS refer to data types guaranteed to be the same size as a C pointer. This guarantee is not necessarily true of any of the other defined C data type macros. (In particular, on 64-bit implementations of Microsoft's Windows operating system, the size of an address does not match the size of an int or long; should XIDAK make available an implementation of MAINSAIL for 64-bit Windows, you should use one of the above macros when you want to declare something corresponding to Microsoft's INT_PTR or LONG_PTR.)

L.1. C Data Type Macros in FLI Parameter Declarations

In Version 16.29 and later of MAINSAIL, you should use the above macros for declaring the type of any variable that might be shared with C, including FLI parameters. Before Version 16.29, these macros are not suitable for use as parameter types in FLI PROCEDUREs, because the FLI compiler did not take explicit sizes of parameter data types into account. For example, an attempt to declare an FLI PROCEDURE:

PROCEDURE p (MODIFIES $CSHORT s);       # does not work before 16.29

would fail in MAINSAIL versions older than 16.29 on big-endian platforms where the size of a C short is 2 bytes and the size of a C long is 4 bytes, since MAINSAIL would treat s as a LONG INTEGER and pass the address of the high-order byte of s rather than the address of the low-order 2 bytes of s.

Before Version 16.29, you should continue to use the data type correspondences listed in the operating-system-specific FLI documentation for parameters, and use the above C data type macros only as the data types of fields of MAINSAIL CLASSes that correspond to C structs. However, future versions of MAINSAIL may change the semantics of explicitly sized FLI parameters in such a way that the C data type macros will be able to be used even for parameters.


previous   next   top   contents   index   framed top   this page unframed

MAINSAIL Language Manual, Appendix L