Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: cleanup

Wiki Markup
\[[ISO/IEC 9899-1999|AA. References#ISO/IEC 9899-1999]\] enumerates several instances where the behavior of accessing thean object or function expanded to be a standard library macro definition is [undefined |BB. Definitions#undefined behavior].

...

Noncompliant Code Example (assert)

In this example, a programmer attempts to access their own verification functionality by suppressing the assert macro and instead sending control to an assert a user-defined assert() function.

Suppose the custom <myassert.h> declares a function assert() which does nonstandard verification, and the standard <assert.h> defines an assert macro as required by the standard.

...

Having this function and attempting to access it does not produce defined produces undefined behavior.

Compliant Solution (assert)

The programmer should place nonstandard verification in a function that does not conflict with the standard library macro assert, e.g. myassert().

Code Block
bgColor#ccccff
#include <myassert.h>
#include <assert.h>

void fullAssert(int e) {
  assert(0 < e); // standard library assert()
  myAssertmyassert(e); // well defined custom assertion function
}

Noncompliant Code Example (

...

redefining errno)

Legacy code is apt to include an incorrect declaration such as the following.

Code Block
bgColor#FFcccc
extern int errno;

Compliant Solution (

...

redefining errno)

The correct way to declare errno is to include the header <errno.h>.

...