Versions Compared

Key

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

...

Consequently, the result of the following noncompliant code depends upon unspecified behavior:

Code Block
bgColor#FFcccc
langc
#include <stdio.h>

int g;

int f(int i) {
  g = i;
  return i;
}

int main(void) {
  int x = f(1) + f(2);
  printf("g = %d\n", g);
  /* ... */
  return 0;
}

...

This compliant solution is independent of the order of evaluation of the operands and can only be interpreted in only one way.

Code Block
bgColor#ccccff
langc
#include <stdio.h>

int g;

int f(int i) {
  g = i;
  return i;
}

int main(void) {
  int x = f(1); 
  x += f(2);
  printf("g = %d\n", g);
  /* ... */
  return 0;
}

...