7. Platform- and compiler-dependent directives for C or C++
There is a large array of Cryptoki-related data types which are defined in the Cryptoki header files. Certain packing- and pointer-related aspects of these types are platform- and compiler-dependent; these aspects are therefore resolved on a platform-by-platform (or compiler-by-compiler) basis outside of the Cryptoki header files by means of preprocessor directives.
This means that when writing C or C++ code, certain preprocessor directives must be issued before including a Cryptoki header file. These directives are described in the remainder of Section .
7.1. Structure packing
Cryptoki structures are packed to occupy as little space as is possible. In particular, on the Win32 and Win16 platforms, Cryptoki structures should be packed with 1-byte alignment. In a UNIX environment, it may or may not be necessary (or even possible) to alter the byte-alignment of structures.
Because different platforms and compilers have different ways of dealing with different types of pointers, Cryptoki requires the following 6 macros to be set outside the scope of Cryptoki:
CK_PTR
CK_PTR is the “indirection string” a given platform and compiler uses to make a pointer to an object. It is used in the following fashion:
typedef CK_BYTE CK_PTR CK_BYTE_PTR;
CK_DEFINE_FUNCTION
CK_DEFINE_FUNCTION(returnType, name), when followed by a parentheses-enclosed list of arguments and a function definition, defines a Cryptoki API function in a Cryptoki library. returnType is the return type of the function, and name is its name. It is used in the following fashion:
CK_DEFINE_FUNCTION(CK_RV, C_Initialize)(
CK_VOID_PTR pReserved
)
{
...
}
CK_DECLARE_FUNCTION
CK_DECLARE_FUNCTION(returnType, name), when followed by a parentheses-enclosed list of arguments and a semicolon, declares a Cryptoki API function in a Cryptoki library. returnType is the return type of the function, and name is its name. It is used in the following fashion:
CK_DECLARE_FUNCTION(CK_RV, C_Initialize)(
CK_VOID_PTR pReserved
);