Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

No other identifiers are reserved. (Note that the POSIX standard extends the set of identifiers reserved by the C Standard to include an open-ended set of its own. See section 2.2, "The Compilation Environment," in IEEE Std 1003.1-20082013.) The behavior of a program that declares or defines an identifier in a context in which it is reserved , or that defines a reserved identifier as a macro name , is undefined. See also undefined behavior 106  in Annex J of the C Standard.

...

In this noncompliant code example, the names of the file scope objects _max_limit and _limit both begin with an underscore. Because it is static, the declaration of _max_limit might seem to be impervious to clashes with names defined by the implementation. However, because the header <stddef.h> is included in order to define size_t, a potential for a name clash exists. (Note, however, that a conforming compiler may implicitly declare reserved names regardless of whether any C standard library header is explicitly included.) In addition, because _limit has external linkage, it may clash with a symbol with the same name defined in the language runtime library even if such a symbol is not declared in any header. Consequently, it is unsafe to start the name of any file scope identifier with an underscore even if its linkage limits its visibility to a single translation unit.

...

In this noncompliant code example, because the C standard library header <inttypes.h> is specified to include <stdint.h>, the name MAX_SIZE conflicts with a standard macro of the same name, used to denote the upper limit of size_t. In addition, although the name INTFAST16_LIMIT_MAX is not defined by the C standard library, it is a reserved identifier because it begins with the INT prefix and ends with the _MAX suffix. (See subclause 7.31.10 of the C Standard [ISO/IEC 9899:2011].)

Code Block
bgColor#ffcccc
langc
#include <inttypes.h>
#include <stdio.h>

static const int_fast16_t INTFAST16_LIMIT_MAX = 12000;

void print_fast16(int_fast16_t val) {
  enum { MAX_SIZE = 80 };
  char buf[MAX_SIZE];
  if (INTFAST16_LIMIT_MAX < val) {
    sprintf(buf, "The value is too large");
  } else {
    snprintf(buf, MAX_SIZE, "The value is %" PRIdFAST16, val);
  }
}

...

This noncompliant example provides definitions for the C standard library functions malloc() and free(). Although this practice is permitted by many traditional implementations of UNIX (e.g., the Dmalloc library), it is disallowed by the C Standard because it is undefined behavior. Even on systems that allow replacing malloc(), doing so without also replacing calloc() and realloc() is likely to cause problems.

...

a macro definition of errno is suppressed in order to access an actual object, or the program defines an identifier with the name errno. [ISO/IEC 9899:2011]

(See subclause 7.5, paragraph 2, and undefined behavior 114 in Annex J of the C Standard.)

...

Code Block
bgColor#ccccff
langc
#include <errno.h>

Implementations conforming to C are required to declare errno in <errno.h>, although some historic implementations failed to do so.

...

Such macros should be used only with great care. See PRE31-C. Avoid Do not perform side effects in arguments to unsafe macros and PRE00-C. Prefer inline or static functions to function-like macros for more information.

...

Bibliography

[IEEE Std 1003.1-20082013]Section 2.2, "The Compilation Environment"
[ISO/IEC 9899:2011]Subclause 7.1.3, "Reserved Identifiers"
Subclause 7.31.10, "Integer Types <stdint.h>"

...