...
Non-Compliant Code Example
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 non-compliant code example defeats the purpose of defining BUFSIZ
as a constant by assuming its value in the following expression:
Code Block | ||
---|---|---|
| ||
#include <stdio.h>
/* ... */
nblocks = nbytes >> 9; /* hard to modify, uses "magic number" */
|
...
This compliant solution uses the identifier assigned to the constant value in the expression.
Code Block | ||
---|---|---|
| ||
#include <stdio.h>
/* ... */
nblocks = nbytes / BUFSIZ;
|
...