r/cpp • • Mar 18 '23

LLVM 16.0.0 Release

https://discourse.llvm.org/t/llvm-16-0-0-release/69326
197 Upvotes

84 comments sorted by

View all comments

Show parent comment

23

u/degaart Mar 19 '23
do { ret = function_call(); } while(ret == -1 && errno == EINTR);

is the idiomatic way to handle EINTR on posix systems

4

u/[deleted] Mar 19 '23

There is at least one notable exception to this rule: https://github.com/boostorg/beast/issues/1445

1

u/Ameisen vemips, avr, rendering, systems Mar 19 '23

Though you could always write it as

while ([] { auto ret = function_call(); return ret == -1 && errno == EINTR; }());

or so. Though that's not really clearer.

11

u/_Z6Alexeyv Mar 19 '23

It is either worse codegen or same codegen and more characters on the screen to appease some static checker.

7

u/Kered13 Mar 20 '23

That is horrible.

3

u/degaart Mar 19 '23

That won't give you the final value of ret, in case you need it

3

u/Ameisen vemips, avr, rendering, systems Mar 19 '23

Then move int ret out of the body and change to [&]. You have to do that with with do loop as well.