1 // Copyright 2023 The Pigweed Authors 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); you may not 4 // use this file except in compliance with the License. You may obtain a copy of 5 // the License at 6 // 7 // https://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 11 // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 12 // License for the specific language governing permissions and limitations under 13 // the License. 14 #pragma once 15 16 // Include these headers as C++ code, in case assert.h is included within an 17 // extern "C" block. 18 #ifdef __cplusplus 19 extern "C++" { 20 #endif // __cplusplus 21 22 #include "pw_assert/assert.h" 23 #include "pw_preprocessor/util.h" 24 25 #ifdef __cplusplus 26 } // extern "C++" 27 #endif // __cplusplus 28 29 // Provide static_assert() for C11 and C17. static_assert is a keyword in C23. 30 #if (defined(__USE_ISOC11) || defined(__STDC_VERSION__) && \ 31 (__STDC_VERSION__ >= 201112L) && \ 32 (__STDC_VERSION__ < 202311L)) && \ 33 !defined(__cplusplus) && !defined(static_assert) 34 #define static_assert _Static_assert 35 #endif // C11 or newer 36 37 // Provide assert() 38 #undef assert 39 #if defined(NDEBUG) // Required by ANSI C standard. 40 #define assert(condition) ((void)0) 41 #else 42 #define assert(condition) PW_ASSERT(condition) 43 #endif // defined(NDEBUG) 44