kwsysPlatformTestsC.c 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /*============================================================================
  2. KWSys - Kitware System Library
  3. Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
  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. /*
  11. Macros to define main() in a cross-platform way.
  12. Usage:
  13. int KWSYS_PLATFORM_TEST_C_MAIN()
  14. {
  15. return 0;
  16. }
  17. int KWSYS_PLATFORM_TEST_C_MAIN_ARGS(argc, argv)
  18. {
  19. (void)argc; (void)argv;
  20. return 0;
  21. }
  22. */
  23. #if defined(__CLASSIC_C__)
  24. # define KWSYS_PLATFORM_TEST_C_MAIN() \
  25. main()
  26. # define KWSYS_PLATFORM_TEST_C_MAIN_ARGS(argc, argv) \
  27. main(argc,argv) int argc; char* argv[];
  28. #else
  29. # define KWSYS_PLATFORM_TEST_C_MAIN() \
  30. main(void)
  31. # define KWSYS_PLATFORM_TEST_C_MAIN_ARGS(argc, argv) \
  32. main(int argc, char* argv[])
  33. #endif
  34. /*--------------------------------------------------------------------------*/
  35. #ifdef TEST_KWSYS_C_HAS_PTRDIFF_T
  36. #include <stddef.h>
  37. int f(ptrdiff_t n) { return n > 0; }
  38. int KWSYS_PLATFORM_TEST_C_MAIN()
  39. {
  40. char* p = 0;
  41. ptrdiff_t d = p - p;
  42. (void)d;
  43. return f(p - p);
  44. }
  45. #endif
  46. /*--------------------------------------------------------------------------*/
  47. #ifdef TEST_KWSYS_C_HAS_SSIZE_T
  48. #include <unistd.h>
  49. int f(ssize_t n) { return (int)n; }
  50. int KWSYS_PLATFORM_TEST_C_MAIN()
  51. {
  52. ssize_t n = 0;
  53. return f(n);
  54. }
  55. #endif