Versions Compared

Key

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

...

Wiki Markup
<ac:structured-macro ac:name="anchor" ac:schema-version="1" ac:macro-id="b275d721286cda8b-16d3a9ce-47884dff-9da38b26-b0e9b4b067bc6b6f10ea8eab"><ac:parameter ac:name="">1</ac:parameter></ac:structured-macro> \[1\] Note that the POSIX ^&#xAE;^ standard extends the set of identifiers reserved by C99 to include an open-ended set of its own. See section [2.2 Compilation Environment|http://www.opengroup.org/onlinepubs/9699919799/functions/V2_chap02.html#tag_15_02] in [IEEE Std 1003.1-2008|AA. Bibliography#IEEE Std 1003.1-2008].

...

Code Block
bgColor#ccccff
#include <stddef.h>

void* my_malloc(size_t nbytes) {
  void *ptr;
  /* allocate storage from own pool and set ptr */
  return ptr;
}

void* my_calloc(size_t nelems, size_t elsize) {
  void *ptr;
  /* allocate storage from own pool and set ptr */
  return ptr;
}

void* my_realloc(void *ptr, size_t nbytes) {
  /* reallocate storage from own pool and set ptr */
  return ptr;
}

void my_free(void *ptr) {
  /* return storage to own pool */
}

Noncompliant Code Example (errno)

Wiki Markup
According \[[ISO/IEC 9899-1999|AA. Bibliography#ISO/IEC 9899-1999]\], the behavior of a program is [undefined |BB. Definitions#undefined behavior] when

a macro definition of errno is suppressed in order to access an actual object, or the program defines an identifier with the name errno.

(See undefined behavior 108 of Annex J.)

The errno identifier expands to a modifiable lvalue that has type int but is not necessarily the identifier of an object. It might expand to a modifiable lvalue resulting from a function call, such as *errno(). It is unspecified whether errno is a macro or an identifier declared with external linkage. If a macro definition is suppressed to access an actual object, or a program defines an identifier with the name errno, the behavior is undefined.

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

Code Block
bgColor#FFcccc

extern int errno;

Compliant Solution (errno)

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

Code Block
bgColor#ccccff

#include <errno.h>

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

Risk Assessment

Using reserved identifiers can lead to incorrect program operation.

...

Tool

Version

Checker

Description

Section

LDRA tool suite

Include Page
c:LDRA_V
c:LDRA_V

 

 

Section

Compass/ROSE

 

 

 

Related Guidelines

...