Interface __SizeFrom2ToConst
Preprocessor macro expanding to an expression
#include <ENDIAN.H>
x = __SizeFrom2ToConst(val)
Description
This is a family of preprocessor macros that convert to or from different endianity. The function of the macro is encoded in parts of its name: Size, From, To, Const.
Arguments
- Size — This may be one of the following:
- 16 — Convert 16-bit unsigned value.
- 32 — Convert 32-bit unsigned value.
- 64 — Convert 64-bit unsigned value.
- From — This is the format from which the conversion should be made:
- CPU — Convert from CPU-native format.
- LE — Convert from little endian.
- BE — Convert from big endian.
- To — This is the format to which the conversion should be made:
- CPU — Convert to CPU-native format.
- LE — Convert to little endian.
- BE — Convert to big endian.
Note: exactly one of From and To must be CPU
. - Const — This specifies if the macro should perform conversion of a constant and generate a C constant expression.
- empty — Convert any expression into a non-constant result.
- _CONST — Convert a constant expression into a constant result.
- val — This is the number to convert. It must be 16-bit, 32-bit or 64-bit unsigned integer (according to Size).
Returns
The if the CPU endianity differs from the requested endianity, the macro will return an argument with swapped bytes. Otherwise the macro will return val unchanged.
See also
ntohs, htons, ntohl, htonl