Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Kitware
GitHub Repository: Kitware/CMake
Path: blob/master/Utilities/KWIML/test/test_abi_endian.h
3153 views
1
/*
2
Copyright Kitware, Inc.
3
Distributed under the OSI-approved BSD 3-Clause License.
4
See accompanying file Copyright.txt for details.
5
*/
6
#include <stdio.h>
7
8
#ifdef __cplusplus
9
# define LANG "C++ "
10
#else
11
# define LANG "C "
12
#endif
13
14
static int test_abi_endian(void)
15
{
16
int result = 1;
17
{
18
#if defined(KWIML_ABI_ENDIAN_ID)
19
int expect;
20
union { short s; unsigned char c[sizeof(short)]; } x;
21
x.s = 1;
22
expect = (x.c[0] == 1 ?
23
KWIML_ABI_ENDIAN_ID_LITTLE : KWIML_ABI_ENDIAN_ID_BIG);
24
printf(LANG "KWIML_ABI_ENDIAN_ID: expected [%d], got [%d]",
25
expect, KWIML_ABI_ENDIAN_ID);
26
if(KWIML_ABI_ENDIAN_ID == expect)
27
{
28
printf(", PASSED\n");
29
}
30
else
31
{
32
printf(", FAILED\n");
33
result = 0;
34
}
35
#else
36
printf(LANG "KWIML_ABI_ENDIAN_ID: unknown, FAILED\n");
37
result = 0;
38
#endif
39
}
40
return result;
41
}
42
43