4 ms·
What does this return? int x = 1; defer x = 2; return x;
by hyperhello 2y ago
What does this return?
int x = 1;
defer x = 2;
return x;
- gizmo686 2y agoThat 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);
- Jtsummers 2y agohttps://thephd.dev/_vendor/future_cxx/technical%20specification/C%20-%20defer/C%20-%20defer%20Technical%20Specification.pdf 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.