Host. More...
Defines | |
#define | VL_YESNO(x) ((x)?"yes":"no") |
Convert a boolean to "yes" or "no" strings. | |
Configuration options | |
#define | VL_DISABLE_THREADS |
Defined if multi-threading support is disabled. | |
#define | VL_DISABLE_SSE2 |
Defined if SSE2 support if disabled. | |
Defining functions | |
#define | VL_EXPORT |
Declares a DLL exported symbol. | |
#define | VL_INLINE |
Adds appropriate inline function qualifier. | |
C preprocessor helper macros | |
#define | VL_STRINGIFY(x) # x |
Convert the argument to a string. | |
#define | VL_XSTRINGIFY(x) VL_STRINGIFY(x) |
Expand and then convert the argument to a string. | |
#define | VL_CAT(x, y) x ## y |
Concatenate two arguments into a lexical unit. | |
#define | VL_XCAT(x, y) VL_CAT(x,y) |
Expand and then concatenate two arguments into a lexical unit. | |
#define | VL_XCAT3(x, y, z) VL_XCAT(VL_XCAT(x,y),z) |
Expand and then concatenate three arguments into a lexical unit. | |
#define | VL_XCAT4(x, y, z, u) VL_XCAT(VL_XCAT3(x,y,z),u) |
Expand and then concatenate four arguments into a lexical unit. | |
#define | VL_XCAT5(x, y, z, u, v) VL_XCAT(VL_XCAT4(x,y,z,u),v) |
Expand and then concatenate five arguments into a lexical unit. | |
Identifying the host operating system | |
#define | VL_OS_LINUX 1 |
Defined if the host operating system is Linux. | |
#define | VL_THREADS_POSIX 1 |
#define | VL_OS_MACOSX 1 |
Defined if the host operating system is Mac OS X. | |
#define | VL_THREADS_POSIX 1 |
#define | VL_OS_WIN 1 |
Defined if the host operating system is Windows (32 or 64) | |
#define | VL_THREADS_WIN 1 |
#define | VL_OS_WIN64 1 |
Defined if the host operating system is Windows-64. | |
#define | VL_THREADS_WIN 1 |
Identifying the host compiler | |
#define | VL_COMPILER_GNUC |
Defined if the host compiler is GNU C. | |
#define | VL_COMPILER_MSC _MSC_VER |
Defined if the host compiler is Microsoft Visual C++. | |
#define | VL_COMPILER_LCC 1 |
Identifying the host CPU architecture | |
#define | VL_ARCH_IX86 300 |
Defined if the host CPU is of the Intel x86 family. | |
#define | VL_ARCH_IA64 |
Defined if the host CPU is of the Intel Architecture-64 family. | |
Identifying the host data model | |
#define | VL_COMPILER_LLP64 |
Defined if the host compiler data model is LLP64. | |
#define | VL_COMPILER_LP64 |
Defined if the host compiler data model is LP64. | |
#define | VL_COMPILER_ILP32 |
Defined if the host compiler data model is ILP32. | |
Identifying the host endianness | |
#define | VL_ARCH_LITTLE_ENDIAN |
Defined if the host CPU is little endian. | |
#define | VL_ARCH_BIG_ENDIAN |
Defined if the host CPU is big endian. | |
Printing the atomic data types | |
#define | VL_FL_INT64 "I64" |
printf length flag for vl_int64 and vl_uint64. | |
#define | VL_FL_INT32 "" |
printf length flag for vl_int32 and vl_uint32. | |
#define | VL_FL_INT16 "h" |
printf length flag for vl_int16 and vl_uint16. | |
#define | VL_FL_INT8 "hh" |
printf length flag for vl_int8 and vl_uint8. | |
#define | VL_FL_INDEX VL_FL_INT64 |
printf length flag for vl_index and vl_uindex | |
#define | VL_FL_INDEX VL_FL_INT32 |
printf length flag for vl_index and vl_uindex | |
#define | VL_FMT_INDEX VL_FL_INDEX "d" |
printf flag for vl_index | |
#define | VL_FMT_INTPTR VL_FMT_INDEX |
printf flag for vl_intptr | |
#define | VL_FMT_UINDEX VL_FL_INDEX "u" |
printf flag for vl_uindex | |
#define | VL_FMT_SIZE VL_FMT_UINDEX |
printf flag for vl_size | |
#define | VL_FMT_UINTPTR VL_FMT_UINDEX |
printf flag for vl_uintptr | |
Atomic data types limits | |
#define | VL_BIG_INT 0x7FFFFFFFL |
Largest integer (math constant) | |
#define | VL_SMALL_INT (- VL_BIG_INT - 1) |
Smallest integer (math constant) | |
#define | VL_BIG_UINT 0xFFFFFFFFUL |
Largest unsigned integer (math constant) | |
Functions | |
char * | vl_static_configuration_to_string_copy () |
Human readable static library configuration. | |
Endianness detection and conversion | |
void | vl_swap_host_big_endianness_8 (void *dst, void *src) |
Host <-> big endian transformation for 8-bytes value. | |
void | vl_swap_host_big_endianness_4 (void *dst, void *src) |
Host <-> big endian transformation for 4-bytes value. | |
void | vl_swap_host_big_endianness_2 (void *dst, void *src) |
Host <-> big endian transformation for 2-bytes value. | |
Obtaining host info at run time | |
void | _vl_x86cpu_info_init (VlX86CpuInfo *self) |
char * | _vl_x86cpu_info_to_string_copy (VlX86CpuInfo const *self) |
Atomic data types | |
#define | VL_TRUE 1 |
true (1) constant | |
#define | VL_FALSE 0 |
false (0) constant | |
typedef long long | vl_int64 |
Signed 64-bit integer. | |
typedef int | vl_int32 |
Signed 32-bit integer. | |
typedef short | vl_int16 |
Signed 16-bit integer. | |
typedef char | vl_int8 |
Signed 8-bit integer. | |
typedef long long unsigned | vl_uint64 |
Unsigned 64-bit integer. | |
typedef int unsigned | vl_uint32 |
Unsigned 32-bit integer. | |
typedef short unsigned | vl_uint16 |
Unsigned 16-bit integer. | |
typedef char unsigned | vl_uint8 |
Unsigned 8-bit integer. | |
typedef int | vl_int |
Same as int . | |
typedef unsigned int | vl_uint |
Same as unsigned int . | |
typedef int | vl_bool |
Boolean. | |
typedef vl_int64 | vl_intptr |
Integer holding a pointer. | |
typedef vl_uint64 | vl_uintptr |
Unsigned integer holding a pointer. | |
typedef vl_uint64 | vl_size |
Unsigned integer holding the size of a memory block. | |
typedef vl_int64 | vl_index |
Signed version of vl_size and vl_uindex. | |
typedef vl_uint64 | vl_uindex |
Same as vl_size. |
Detailed Description
This module provides functionalities to identify the host operating system, C compiler, and CPU architecture. It also provides a few features to abstract from such details.
Host operating system
The module defines a symbol to identify the host operating system: VL_OS_WIN for Windows, VL_OS_LINUX for Linux, VL_OS_MACOSX for Mac OS X, and so on.
Host compiler
The module defines a symbol to identify the host compiler: VL_COMPILER_MSC for Microsoft Visual C++, VL_COMPILER_GNUC for GNU C, and so on. The (integer) value of such symbols corresponds the version of the compiler.
The module defines a symbol to identify the data model of the compiler: VL_COMPILER_ILP32, VL_COMPILER_LP64, or VL_COMPILER_LLP64 (see Sect. Data models). For convenience, it also defines a number of atomic types of prescribed width (vl_int8, vl_int16, vl_int32, etc.).
- Remarks:
- While some of such functionalities are provided by the standard header
stdint.h
, the latter is not supported by all platforms.
Data models
The C language defines a number of atomic data types (such as char
, short
, int
and so on). The number of bits (width) used to represent each data type depends on the compiler data model. The following table summarizes the relevant conventions:
Data model | short | int | long | long long | void* | Compiler |
ILP32 | 16 | 32 | 32 | 64 | 32 | common 32 bit architectures |
LP64 | 16 | 32 | 64 | 64 | 64 | UNIX-64 (Linux, Mac OS X) |
ILP64 | 16 | 64 | 64 | 64 | 64 | Alpha, Cray |
SLIP64 | 64 | 64 | 64 | 64 | 64 | |
LLP64 | 16 | 32 | 32 | 64 | 64 | Windows-64 |
Other compiler-specific features
The module provides the macro VL_EXPORT to declare symbols exported from the library and the macro VL_INLINE to declare inline functions. Such features are not part of the C89 standard, and change depending on the compiler.
- Example:
- The following header file declares a function
f
that should be visible from outside the library.Notice that the macro VL_EXPORT needs not to be included again when the function is defined.#include <vl/generic.h> VL_EXPORT void f () ; VL_EXPORT int i ;
- Example:
- The following header file declares an inline function
f:
#include <vl/generic.h> VL_INLINE int f() ; VL_INLINE int f() { return 1 ; }
Here the first instruction defines the function f
, where the second declares it. Notice that since this is an inline function, its definition must be found in the header file rather than in an implementation file. Notice also that definition and declaration can be merged.
These macros translate according to the following tables:
Platform | Macro name | Value when building the library | Value when importing the library |
Unix/GCC | VL_EXPORT | empty (assumes -visibility=hidden GCC option) | __attribute__((visibility ("default"))) |
Win/Visual C++ | VL_EXPORT | __declspec(dllexport) | __declspec(dllimport) |
Platform | Macro name | Value |
Unix/GCC | VL_INLINE | static inline |
Win/Visual C++ | VL_INLINE | static __inline |
Host CPU architecture
The module defines a symbol to identify the host CPU architecture: VL_ARCH_IX86 for Intel x86, VL_ARCH_IA64 for Intel 64, and so on.
Endianness
The module defines a symbol to identify the host CPU endianness: VL_ARCH_BIG_ENDIAN for big endian and VL_ARCH_LITTLE_ENDIAN for little endian. The functions vl_swap_host_big_endianness_8(), vl_swap_host_big_endianness_4(), vl_swap_host_big_endianness_2() to change the endianness of data (from/to host and network order).
Recall that endianness concerns the way multi-byte data types (such as 16, 32 and 64 bits integers) are stored into the addressable memory. All CPUs uses a contiguous address range to store atomic data types (e.g. a 16-bit integer could be assigned to the addresses 0x10001
and 0x10002
), but the order may differ.
- The convention is big endian, or in network order, if the most significant byte of the multi-byte data types is assigned to the smaller memory address. This is the convention used for instance by the PPC architecture.
- The convention is little endian if the least significant byte is assigned to the smaller memory address. This is the convention used for instance by the x86 architecture.
- Remarks:
- The names “big endian” and “little endian” are a little confusing. “Big endian” means “big endian first”, i.e. the address of the most significant byte comes first. Similarly, “little endian” means “little endian first”, in the sense that the address of the least significant byte comes first.
Endianness is a concern when data is either exchanged with processors that use different conventions, transmitted over a network, or stored to a file. For the latter two cases, one usually saves data in big endian (network) order regardless of the host CPU.
host-threads
The file defines #VL_THREADS_WIN if multi-threading support is enabled and the host supports Windows threads and #VL_THREADS_POSIX if it supports POSIX threads.
Define Documentation
#define VL_ARCH_BIG_ENDIAN |
- See also:
- Endianness
#define VL_ARCH_IA64 |
- See also:
- Host CPU architecture
#define VL_ARCH_IX86 300 |
- See also:
- Host CPU architecture
#define VL_ARCH_LITTLE_ENDIAN |
- See also:
- Endianness
#define VL_CAT | ( | x, | |
y | |||
) | x ## y |
- Parameters:
-
x first argument to be concatenated. y second argument to be concatenated.
This macro concatenates its arguments into a single lexical unit by means of the ##
preprocessor operator. Notice that arguments concatenated by ##
are not pre-expanded by the C preprocessor. To macro-expand the arguments and then concatenate them,use VL_XCAT.
- See also:
- VL_XCAT
#define VL_COMPILER_GNUC |
(__GNUC__ * 10000 \ + __GNUC_MINOR__ * 100)
This macro is defined if the compiler is GNUC. Its value is calculated as
10000 * MAJOR + 100 * MINOR + PATCHLEVEL
- See also:
- Host compiler
#define VL_COMPILER_ILP32 |
- See also:
- Data models
#define VL_COMPILER_LLP64 |
- See also:
- Data models
#define VL_COMPILER_LP64 |
- See also:
- Data models
#define VL_COMPILER_MSC _MSC_VER |
- See also:
- Host compiler
#define VL_DISABLE_SSE2 |
Define this symbol to disable SSE2 support.
#define VL_DISABLE_THREADS |
Define this symbol to disable multi-threading support.
#define VL_EXPORT |
- See also:
- Other compiler-specific features
#define VL_INLINE |
- See also:
- Other compiler-specific features
#define VL_STRINGIFY | ( | x | ) | # x |
- Parameters:
-
x value to be stringified.
This macro stringifies the argument x by means of the #
prerpocessor operator.
The standard C preprocessor does not prescan arguments which are stringified, so
#define A B char const * str = VL_STRINGIFY(A) ;
initializes str
with a pointer to the string "A"
, which mihgt be unexpected. To fix this issue, you can use VL_XSTRINGIFY.
- See also:
- VL_XSTRINGIFY
#define VL_XCAT | ( | x, | |
y | |||
) | VL_CAT(x,y) |
#define VL_XCAT3 | ( | x, | |
y, | |||
z | |||
) | VL_XCAT(VL_XCAT(x,y),z) |
#define VL_XCAT4 | ( | x, | |
y, | |||
z, | |||
u | |||
) | VL_XCAT(VL_XCAT3(x,y,z),u) |
#define VL_XCAT5 | ( | x, | |
y, | |||
z, | |||
u, | |||
v | |||
) | VL_XCAT(VL_XCAT4(x,y,z,u),v) |
#define VL_XSTRINGIFY | ( | x | ) | VL_STRINGIFY(x) |
- Parameters:
-
x value to be macro-expanded and converted.
This macro macro-expands the argument x and stringifies the result of the expansion. For instance
#define A B char const * str = VL_STRINGIFY(A) ;
initializes str
with a pointer to the string "B"
.
- See also:
- VL_STRINGIFY
#define VL_YESNO | ( | x | ) | ((x)?"yes":"no") |
Function Documentation
char* vl_static_configuration_to_string_copy | ( | ) |
- Returns:
- a new string with the static configuration.
The string includes information about the compiler, the host, and other static configuration parameters. The string must be released by vl_free.
void vl_swap_host_big_endianness_2 | ( | void * | dst, |
void * | src | ||
) | [inline] |
- Parameters:
-
dst destination 2-byte buffer. src source 2-byte bufffer.
- See also:
- Endianness.
void vl_swap_host_big_endianness_4 | ( | void * | dst, |
void * | src | ||
) | [inline] |
- Parameters:
-
dst destination 4-byte buffer. src source 4-byte bufffer.
- See also:
- Endianness.
void vl_swap_host_big_endianness_8 | ( | void * | dst, |
void * | src | ||
) | [inline] |
- Parameters:
-
dst destination 8-byte buffer. src source 8-byte bufffer.
- See also:
- Endianness.