Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: updated for consistency with TS 17961

...

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

Noncompliant Code Example (malloc(), free())

In this noncompliant example, the identifiers for the C Standard Library functions malloc() and free() are reserved.

Code Block
bgColor#FFcccc
langc
void *malloc(size_t nbytes) {  /* violation */
  void *ptr;
  /* ... */
  /* allocate storage from own pool and set ptr */
  return ptr;
}
 
void free(void *ptr) {  /* violation */
  /* ... */
  /* return storage to own pool */
}

Compliant Solution ( malloc(), free() )

This complaint example changes the names of the identfiers to malloc_custom() and free_custom().

Code Block
bgColor#ccccff
langc
void *malloc_custom(size_t nbytes) {  
  void *ptr;
  /* ... */
  /* allocate storage from own pool and set ptr */
  return ptr;
}
 
void free_custom(void *ptr) {  
  /* ... */
  /* return storage to own pool */
}

Risk Assessment

Using reserved identifiers can lead to incorrect program operation.

...

Bibliography

[IEEE Std 1003.1-2008]Section 2.2 "The Compilation Environment"
[ISO/IEC 9899:2011]Section 7.1.3, "Reserved Identifiers"

...