...
Suppose the custom <myassert.h> declares a function assert() that does nonstandard verification, and the standard <assert.h> defines an assert macro as required by the standard.
| Code Block | ||||
|---|---|---|---|---|
| ||||
#include <myassert.h>
#include <assert.h>
void fullAssert(int e) {
assert(0 < e); // invoke standard library assert()
(assert)(0 < e); // assert() macro suppressed, calling function assert()
}
|
...
The programmer should place nonstandard verification in a function that does not conflict with the standard library macro assert, for example, myassert().
| Code Block | ||||
|---|---|---|---|---|
| ||||
#include <myassert.h>
#include <assert.h>
void fullAssert(int e) {
assert(0 < e); // standard library assert()
myassert(e); // well defined custom assertion function
}
|
...
Legacy code is apt to include an incorrect declaration, such as the following.
| Code Block | ||||
|---|---|---|---|---|
| ||||
extern int errno; |
Compliant Solution (Redefining errno)
The correct way to declare errno is to include the header <errno.h>.
| Code Block | ||||
|---|---|---|---|---|
| ||||
#include <errno.h> |
Implementations conforming to C99 are required to declare errno in <errno.h>, although some historic implementations failed to do so.
...