| Defined in header
|
||
| #define __STDC_ENDIAN_LITTLE__ /* implementation-defined */ |
(1) | (since C23) |
| #define __STDC_ENDIAN_BIG__ /* implementation-defined */ |
(2) | (since C23) |
| #define __STDC_ENDIAN_NATIVE__ /* implementation-defined */ |
(3) | (since C23) |
Indicates the endianness of all scalar types:
- If all scalar types are little-endian,
__STDC_ENDIAN_NATIVE__equals__STDC_ENDIAN_LITTLE__. - If all scalar types are big-endian,
__STDC_ENDIAN_NATIVE__equals__STDC_ENDIAN_BIG__. - If the platform uses neither little-endian nor big-endian,
__STDC_ENDIAN_NATIVE__equals neither__STDC_ENDIAN_BIG__nor__STDC_ENDIAN_LITTLE__. - The values of the integer constant expressions for
__STDC_ENDIAN_BIG__and__STDC_ENDIAN_LITTLE__are not equal.
Example
#include <stdbit.h>
#include <stdio.h>
int main()
{
switch(__STDC_ENDIAN_NATIVE__)
{
case __STDC_ENDIAN_LITTLE__:
printf("__STDC_ENDIAN_LITTLE__\n");
break;
case __STDC_ENDIAN_BIG__:
printf("__STDC_ENDIAN_BIG__\n");
break;
default:
printf("mixed-endian\n");
}
return __STDC_ENDIAN_NATIVE__;
}mixed-endianSee also
| C++ documentation for endian
|
Content from this page on cppreference.com, licensed under CC-BY-SA 3.0 and GFDL. Modified: restyled, site navigation removed, code windows added. Offline snapshot of 9 February 2025.