VSF Documented
esp_assert.h
Go to the documentation of this file.
1/*****************************************************************************
2 * Copyright(C)2009-2026 by VSF Team *
3 * *
4 * Licensed under the Apache License, Version 2.0 (the "License"); *
5 * you may not use this file except in compliance with the License. *
6 * You may obtain a copy of the License at *
7 * *
8 * http://www.apache.org/licenses/LICENSE-2.0 *
9 * *
10 * Unless required by applicable law or agreed to in writing, software *
11 * distributed under the License is distributed on an "AS IS" BASIS, *
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
13 * See the License for the specific language governing permissions and *
14 * limitations under the License. *
15 * *
16 ****************************************************************************/
17
18/*
19 * Clean-room re-implementation of ESP-IDF public API "esp_assert.h".
20 *
21 * Baseline: ESP-IDF v5.1 public API.
22 */
23
24#ifndef __VSF_ESPIDF_ESP_ASSERT_H__
25#define __VSF_ESPIDF_ESP_ASSERT_H__
26
27#include <assert.h>
28
29/* C17 / C++17 standard static_assert */
30#define ESP_STATIC_ASSERT static_assert
31
32/* Compile-time assert when condition is constant, runtime assert otherwise */
33#ifndef __cplusplus
34#define TRY_STATIC_ASSERT(CONDITION, MSG) do { \
35 ESP_STATIC_ASSERT(__builtin_choose_expr(__builtin_constant_p(CONDITION), \
36 (CONDITION), 1), #MSG); \
37 assert(#MSG && (CONDITION)); \
38 } while(0)
39#else
40#define TRY_STATIC_ASSERT(CONDITION, MSG) do { \
41 if (__builtin_constant_p(CONDITION) && !(CONDITION)) { \
42 extern __attribute__((error(#MSG))) void failed_compile_time_assert(void); \
43 failed_compile_time_assert(); \
44 } \
45 assert(#MSG && (CONDITION)); \
46 } while(0)
47#endif
48
49#endif // __VSF_ESPIDF_ESP_ASSERT_H__
Generated from commit: vsfteam/vsf@c3767bf