Hacker News new | ask | show | jobs
by hyperhello 499 days ago
What does this return?

  int x = 1;
  defer x = 2;
  return x;
1 comments

That will return 1. The defered code is executed after the return value is computed. This lets you do things like:

  char *str = foo();
  defer { free(str); }
  return strlen(str);
https://thephd.dev/_vendor/future_cxx/technical%20specificat...

Right, there's a demonstration of GP's question (or a variation) on page 10 of the draft technical specification.