assert.h: reintroduce headers guard for function declarations.
The POSIX standard requires us to allow assert.h to be included multiple times with differnt values of NDEBUG. So we can't have a global header guard on the files. However, we must also make sure that we don't declare functions multiple times in that case. Re-introduce an header guard on the part of the file where we declare functions, only. Fixes lots of warnings when building Netsurf.
This commit is contained in:
parent
0a6d595951
commit
75d1eb3a59
@ -3,19 +3,19 @@
|
|||||||
* Distributed under the terms of the MIT License.
|
* Distributed under the terms of the MIT License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* Include guards are omitted, as assert.h is required
|
/* Include guards are only on part of the file, as assert.h is required
|
||||||
to support being included multiple times.
|
to support being included multiple times.
|
||||||
|
|
||||||
E.g. the following is required to be valid:
|
E.g. the following is required to be valid:
|
||||||
|
|
||||||
#undef NDEBUG
|
#undef NDEBUG
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
|
||||||
assert(0); // this assertion will be triggered
|
assert(0); // this assertion will be triggered
|
||||||
|
|
||||||
#define NDEBUG
|
#define NDEBUG
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
|
||||||
assert(0); // this assertion will not be triggered
|
assert(0); // this assertion will not be triggered
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@ -24,6 +24,9 @@
|
|||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
/* defining NDEBUG disables assert() functionality */
|
/* defining NDEBUG disables assert() functionality */
|
||||||
|
|
||||||
|
#ifndef _ASSERT_H_
|
||||||
|
#define _ASSERT_H_
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
@ -40,6 +43,8 @@ extern void __assert_perror_fail(int error, const char *file,
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#endif /* !_ASSERT_H_ */
|
||||||
|
|
||||||
#define assert(assertion) \
|
#define assert(assertion) \
|
||||||
((assertion) ? (void)0 : __assert_fail(#assertion, __FILE__, __LINE__, __PRETTY_FUNCTION__))
|
((assertion) ? (void)0 : __assert_fail(#assertion, __FILE__, __LINE__, __PRETTY_FUNCTION__))
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user