[PATCH] libio: Add small optimization on fmemopen

Paul Eggert eggert@cs.ucla.edu
Wed Sep 21 18:43:00 GMT 2016


On 09/21/2016 11:26 AM, Adhemerval Zanella wrote:
> my idea to use this workaround is
> to avoid possible issues with faulty compilers.

That's my thought as well. Although we can argue that the C standard, 
GCC, valgrind, etc. are all faulty, possibly the C standard etc. won't 
change (after all, there is a performance advantage to GCC's current 
behavior) and our code would continue to be over the edge.

We could document this more clearly by having a macro 
FLEXMEMBER_NEEDS_ALIGNMENT specifying whether flexible array member 
sizes require alignment. The default could be true to be safe for 
current platforms, and the macro could be false on (future?) platforms 
known to not require aligned allocation of flexible array members. Then 
we could say something like this:

   size_t clen = sizeof (fmemopen_cookie_t);
   if (FLEXMEMBER_NEEDS_ALIGNMENT)
     clen += _Alignof (fmemopen_cookie_t) - 1;



More information about the Libc-alpha mailing list