• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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() on >=C11
30 #if (defined(__USE_ISOC11) ||                                       \
31      defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L)) && \
32     !defined(__cplusplus)
33 #define static_assert _Static_assert
34 #endif  // C11 or newer
35 
36 // Provide assert()
37 #undef assert
38 #if defined(NDEBUG)  // Required by ANSI C standard.
39 #define assert(condition) ((void)0)
40 #else
41 #define assert(condition) PW_ASSERT(condition)
42 #endif  // defined(NDEBUG)
43