Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Changed write up to match code example, changed examples for consistency

...

In this compliant solution, names of no- file-scope objects do not begin with an underscore and hence do not encroach on the reserved name space:

...

Code Block
bgColor#ffcccc
langc
#include <inttypes.h>   /* For int_fast16_t and PRIdFAST16 */
#include <stdio.h>	    /* For sprintf and snprintf */

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);
  }
  /* ... */
}

Compliant Solution (Reserved Macros)

...

Code Block
bgColor#ccccff
langc
#include <inttypes.h>   /* For int_fast16_t and PRIdFAST16 */
#include <stdio.h>	    /* For sprintf and snprintf */
 
static const int_fast16_t MY_INTFAST16_UPPER_LIMIT = 12000;

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

Noncompliant Code Example (Identifiers with External Linkage)

...