| 1 | // Licensed to the .NET Foundation under one or more agreements. |
| 2 | // The .NET Foundation licenses this file to you under the MIT license. |
| 3 | // See the LICENSE file in the project root for more information. |
| 4 | |
| 5 | /*++ |
| 6 | |
| 7 | |
| 8 | |
| 9 | |
| 10 | |
| 11 | --*/ |
| 12 | |
| 13 | #ifndef __PAL_ASSERT_H__ |
| 14 | #define __PAL_ASSERT_H__ |
| 15 | |
| 16 | #ifdef __cplusplus |
| 17 | extern "C" { |
| 18 | #endif |
| 19 | |
| 20 | #ifdef __cplusplus |
| 21 | // |
| 22 | // C_ASSERT() can be used to perform many compile-time assertions: |
| 23 | // type sizes, field offsets, etc. |
| 24 | // |
| 25 | #define C_ASSERT(e) static_assert(e, #e) |
| 26 | |
| 27 | // |
| 28 | // CPP_ASSERT() can be used within a class definition, to perform a |
| 29 | // compile-time assertion involving private names within the class. |
| 30 | // |
| 31 | #define CPP_ASSERT(n, e) static_assert(e, #e) |
| 32 | |
| 33 | #endif // __cplusplus |
| 34 | |
| 35 | #if defined(_DEBUG) |
| 36 | #define _ASSERTE(e) do { \ |
| 37 | if (!(e)) { \ |
| 38 | fprintf (stderr, \ |
| 39 | "ASSERT FAILED\n" \ |
| 40 | "\tExpression: %s\n" \ |
| 41 | "\tLocation: line %d in %s\n" \ |
| 42 | "\tFunction: %s\n" \ |
| 43 | "\tProcess: %d\n", \ |
| 44 | #e, __LINE__, __FILE__, __FUNCTION__, \ |
| 45 | GetCurrentProcessId()); \ |
| 46 | DebugBreak(); \ |
| 47 | } \ |
| 48 | }while (0) |
| 49 | #else // !DEBUG |
| 50 | #define _ASSERTE(e) ((void)0) |
| 51 | #endif |
| 52 | |
| 53 | #ifndef assert |
| 54 | #define assert(e) _ASSERTE(e) |
| 55 | #endif // assert |
| 56 | |
| 57 | #ifdef __cplusplus |
| 58 | } |
| 59 | #endif |
| 60 | |
| 61 | #endif // __PAL_ASSERT_H__ |
| 62 | |