haiku/headers/posix/assert.h
Trung Nguyen ea2870c839 headers: Define static_assert for C11
Defines the `static_assert` macro in `assert.h` as required by
the C11 standard.

Change-Id: Ic25dc99537f995404b7b4280b72c6000a293a1df
Reviewed-on: https://review.haiku-os.org/c/haiku/+/6916
Reviewed-by: waddlesplash <waddlesplash@gmail.com>
Tested-by: Commit checker robot <no-reply+buildbot@haiku-os.org>
Reviewed-by: Niels Sascha Reedijk <niels.reedijk@gmail.com>
2023-09-04 05:58:31 +00:00

58 lines
1.3 KiB
C

/*
* Copyright 2004-2015 Haiku, Inc. All Rights Reserved.
* Distributed under the terms of the MIT License.
*/
/* Include guards are only on part of the file, as assert.h is required
to support being included multiple times.
E.g. the following is required to be valid:
#undef NDEBUG
#include <assert.h>
assert(0); // this assertion will be triggered
#define NDEBUG
#include <assert.h>
assert(0); // this assertion will not be triggered
*/
#undef assert
#ifndef NDEBUG
/* defining NDEBUG disables assert() functionality */
#ifndef _ASSERT_H_
#define _ASSERT_H_
#ifdef __cplusplus
extern "C" {
#endif
extern void __assert_fail(const char *assertion, const char *file,
unsigned int line, const char *function)
__attribute__ ((noreturn));
extern void __assert_perror_fail(int error, const char *file,
unsigned int line, const char *function)
__attribute__ ((noreturn));
#ifdef __cplusplus
}
#endif
#endif /* !_ASSERT_H_ */
#define assert(assertion) \
((assertion) ? (void)0 : __assert_fail(#assertion, __FILE__, __LINE__, __PRETTY_FUNCTION__))
#else /* NDEBUG */
# define assert(condition) ((void)0)
#endif
#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L && !defined(static_assert)
# define static_assert _Static_assert
#endif