Versions Compared

Key

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

...

If an attempt is made to modify the result of a function call or to access it after the next sequence point, the behavior is undefined.

Thus, the result of a function call after a subsequent access point must never be accessed or modified.

Non-Compliant Code Example

In C, the lifetime of a return value ends at the next sequence pointThe following non-compliant code attempts to retrieve a field from a struct that is returned by a function call.

Code Block
bgColor#FFCCCC
#include <stdio.h>

struct X { char a[6]; };

struct X addressee(void) {
  struct X result = { "world" };
  return result;
}

int main(void) {
  printf("Hello, %s!\n", addressee().a);
  return 0;
}

In C, the lifetime of a return value ends at the next sequence point. This program has undefined behavior because there is a sequence point before printf() is called, and printf() accesses the result of the call to addressee().

...