test_ABI_endian.h.in 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. /*============================================================================
  2. Kitware Information Macro Library
  3. Copyright 2010-2011 Kitware, Inc.
  4. Distributed under the OSI-approved BSD License (the "License");
  5. see accompanying file Copyright.txt for details.
  6. This software is distributed WITHOUT ANY WARRANTY; without even the
  7. implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  8. See the License for more information.
  9. ============================================================================*/
  10. #include <stdio.h>
  11. #ifdef __cplusplus
  12. # define LANG "C++ "
  13. #else
  14. # define LANG "C "
  15. #endif
  16. static int test_ABI_endian(void)
  17. {
  18. int result = 1;
  19. {
  20. #if defined(@KWIML@_ABI_ENDIAN_ID)
  21. int expect;
  22. union { short s; unsigned char c[sizeof(short)]; } x;
  23. x.s = 1;
  24. expect = (x.c[0] == 1 ?
  25. @KWIML@_ABI_ENDIAN_ID_LITTLE : @KWIML@_ABI_ENDIAN_ID_BIG);
  26. printf(LANG "@KWIML@_ABI_ENDIAN_ID: expected [%d], got [%d]",
  27. expect, @KWIML@_ABI_ENDIAN_ID);
  28. if(@KWIML@_ABI_ENDIAN_ID == expect)
  29. {
  30. printf(", PASSED\n");
  31. }
  32. else
  33. {
  34. printf(", FAILED\n");
  35. result = 0;
  36. }
  37. #else
  38. printf(LANG "@KWIML@_ABI_ENDIAN_ID: unknown, FAILED\n");
  39. result = 0;
  40. #endif
  41. }
  42. return result;
  43. }