Program Listing for File cmb_assert.h
↰ Return to documentation for file (include/cmb_assert.h)
/*
* Copyright (c) Asbjørn M. Bonvik 1993-1995, 2025-26.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef CIMBA_CMB_ASSERT_H
#define CIMBA_CMB_ASSERT_H
[[noreturn]]
extern void cmi_assert_failed(const char *sourcefile,
const char *func,
int line,
const char *condition);
#ifndef NASSERT
#ifndef NDEBUG
#define cmb_assert_debug(x) ((x) ? (void)(0) : (cmi_assert_failed(__FILE_NAME__, __func__, __LINE__, #x)))
#else
#define cmb_assert_debug(x) do { (void)sizeof(x); } while (0)
#endif /* ifndef NDEBUG */
#define cmb_assert_release(x) ((x) ? (void)(0) : (cmi_assert_failed(__FILE_NAME__, __func__, __LINE__, #x)))
#else
#define cmb_assert_debug(x) do { (void)sizeof(x); } while (0)
#define cmb_assert_release(x) do { (void)sizeof(x); } while (0)
#endif
#define cmb_assert(x) cmb_assert_debug(x)
#define cmb_assert_always(x) ((x) ? (void)(0) : (cmi_assert_failed(__FILE_NAME__, __func__, __LINE__, #x)))
#define cmb_unused(x) ((void)(x))
#endif /* CIMBA_CMB_ASSERT_H */