Versions Compared

Key

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

...

Code Block
bgColor#CCCCFF
int buf[INTBUFSIZE];
int *buf_ptr = buf;

while (havedata() && buf_ptr < (buf + INTBUFSIZE)) {
    *buf_ptr++ = parseint(getdata());
}

A better solution maybe to use the address of the non-existent element following the end of the array as follows:

Code Block
bgColor#CCCCFF

int buf[INTBUFSIZE];
int *buf_ptr = buf;

while (havedata() && buf_ptr < &buf[INTBUFSIZE] {
  *buf_ptr++ = parseint(getdata());
}

This works because C99 endorses existing practice by guaranteeing that it's permissible to use the address of bufINTBUFSIZE even though no such element exists.

Non-Compliant Code Example

...