pal_assert.h 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. //
  2. // Copyright (c) Microsoft. All rights reserved.
  3. // Licensed under the MIT license. See LICENSE file in the project root for full license information.
  4. //
  5. /*++
  6. --*/
  7. #ifndef __PAL_ASSERT_H__
  8. #define __PAL_ASSERT_H__
  9. #ifdef __cplusplus
  10. extern "C" {
  11. #endif
  12. #ifdef __cplusplus
  13. //
  14. // C_ASSERT() can be used to perform many compile-time assertions:
  15. // type sizes, field offsets, etc.
  16. //
  17. #define C_ASSERT(e) static_assert(e, #e)
  18. //
  19. // CPP_ASSERT() can be used within a class definition, to perform a
  20. // compile-time assertion involving private names within the class.
  21. //
  22. #define CPP_ASSERT(n, e) static_assert(e, #e)
  23. #endif // __cplusplus
  24. #if defined(_DEBUG)
  25. #define _ASSERTE(e) do { \
  26. if (!(e)) { \
  27. fprintf (stderr, \
  28. "ASSERT FAILED\n" \
  29. "\tExpression: %s\n" \
  30. "\tLocation: line %d in %s\n" \
  31. "\tFunction: %s\n" \
  32. "\tProcess: %d\n", \
  33. #e, __LINE__, __FILE__, __FUNCTION__, \
  34. GetCurrentProcessId()); \
  35. __builtin_trap(); \
  36. } \
  37. }while (0)
  38. #else // !DEBUG
  39. #define _ASSERTE(e) ((void)0)
  40. #endif
  41. #ifndef assert
  42. #define assert(e) _ASSERTE(e)
  43. #endif // assert
  44. #ifdef __cplusplus
  45. }
  46. #endif
  47. #endif // __PAL_ASSERT_H__