Hi guys, On Wed, Jun 12, 2019 at 10:31:37PM +0200, Vincent Bernat wrote: > ? 12 juin 2019 20:47 +02, Tim Duesterhus <t...@bastelstu.be>: > > > - write(2, trash.area, trash.data); > > + shut_your_big_mouth_gcc(write(2, trash.area, trash.data));
Now merged, thanks Tim! > An alternative not discussed in 89efaed6b67b (which introduced this > function) is to use "(void)!": > > (void)!write(2, trash.area, trash.data); > > For an entertaining discussion, see: > > https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66425 > > Of course, like the "if (foo()) /* do nothing */;", this can be broken > in the future. Oh that's a very interesting lecture. And indeed I wouldn't trust it for a long time, as it can become quite easy for future compilers to detect that the transformed variable is useless. There's actually a trick as well consisting in using two variables each assigned to the other one. The compiler cannot detect anymore that any of them is not used : static inline void unused(int ret) { int a, b; // mark all variables as read and written a = ret; b = a; a = b; } Yes that's ugly as well, I strongly prefer this in practice : static inline void unused(int ret) { asm("" ::r(ret)); } At least I'm certain it doesn't emit any code. Willy