test_abi_endian.h 842 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  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. #ifdef __cplusplus
  8. # define LANG "C++ "
  9. #else
  10. # define LANG "C "
  11. #endif
  12. static int test_abi_endian(void)
  13. {
  14. int result = 1;
  15. {
  16. #if defined(KWIML_ABI_ENDIAN_ID)
  17. int expect;
  18. union { short s; unsigned char c[sizeof(short)]; } x;
  19. x.s = 1;
  20. expect = (x.c[0] == 1 ?
  21. KWIML_ABI_ENDIAN_ID_LITTLE : KWIML_ABI_ENDIAN_ID_BIG);
  22. printf(LANG "KWIML_ABI_ENDIAN_ID: expected [%d], got [%d]",
  23. expect, KWIML_ABI_ENDIAN_ID);
  24. if(KWIML_ABI_ENDIAN_ID == expect)
  25. {
  26. printf(", PASSED\n");
  27. }
  28. else
  29. {
  30. printf(", FAILED\n");
  31. result = 0;
  32. }
  33. #else
  34. printf(LANG "KWIML_ABI_ENDIAN_ID: unknown, FAILED\n");
  35. result = 0;
  36. #endif
  37. }
  38. return result;
  39. }