Versions Compared

Key

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

...

The header stdio.h defines the BUFSIZ macro which expands to an integer constant expression that is the size of the buffer used by the setbuf() function. This noncompliant code example defeats the purpose of defining BUFSIZ as a constant by assuming its value in the following expression:

Code Block
bgColor#FFcccc
langc
#include <stdio.h>
/* ... */
nblocks = 1 + ((nbytes - 1) >> 9); /* BUFSIZ = 512 = 2^9 */

...

This compliant solution uses the identifier assigned to the constant value in the expression.

Code Block
bgColor#ccccff
langc
#include <stdio.h>
/* ... */
nblocks = 1 + (nbytes - 1) / BUFSIZ;

...