Declare variables with non-ANSI storage-class modifiers

The ANSI C standards define a set of storage-class specifiers for variable declarations. The C compilers in Windows™ environments often support non-ANSI storage-class specifiers. To provide support for these non-ANSI storage-class specifiers in Informix® ESQL/C host-variable declarations, the Informix ESQL/C preprocessor supports the form of the ANSI syntax, as shown.


1   EXEC SQL BEGIN DECLARE SECTION; + ; %Declaration  EXEC SQL END DECLARE SECTION;
1 + ; $ %Declaration
Declaration

1  @?  ('" modifier name ")  variable type?  (" modifier name ")  variable name
Element Purpose Restrictions Syntax
modifier name Text that you want to pass to the C compiler for translation.

This text is usually the name of the storage-class modifier.

The modifier must be valid for your C compiler or be a name that you define in your program. See your C compiler documentation.
variable name Identifier name of the ESQL/C host variable None. See Declare a host variable.
variable type Data type of the ESQL/C host variable The type must be a valid C or ESQL/C data type. See Declare a host variable.
For example, the Microsoft™ Visual C++ compiler supports the declspec compiler directive to enable you to declare extended storage-class attributes. This compiler directive has the following syntax:
__declspec(attribute) var_type var_name;

In this example, attribute is a supported keyword (such as thread, dllimport, or dllexport), var_type is the data type of the variable, and var_name is the variable name.

To enable you to declare Informix ESQL/C host variables as extended storage-class variables, the Informix ESQL/C preprocessor supports the declspec directive with the following syntax:
@("__declspec(attribute)") var_type var_name;
In this example, attribute, var_type, and var_name are the same as in the previous example. You might find it convenient to declare a macro for the declspec syntax. The following example declares threadCount as an instance-specific integer variable of the thread-extended storage class:
#define DLLTHREAD __declspec(thread)


EXEC SQL BEGIN DECLARE SECTION;
   @("DLLTHREAD") int threadCount;
EXEC SQL END DECLARE SECTION;
This example creates the DLLTHREAD macro to simplify the declaration of thread-extended storage-class attributes. You can declare similar macros to simplify declaration of variables to be exported (or imported) to the dynamic link library (DLL), as follows:
#define DLLEXPORT __declspec(dllexport);


EXEC SQL BEGIN DECLARE SECTION;
   @("DLLEXPORT") int winHdl;
EXEC SQL END DECLARE SECTION;