svn commit: r292809 - head/lib/libc/stdio

Bruce Evans brde at optusnet.com.au
Wed Dec 30 06:44:56 UTC 2015


On Wed, 30 Dec 2015, David Chisnall wrote:

> On 30 Dec 2015, at 00:48, Bruce Evans <brde at optusnet.com.au> wrote:
>>
>> - C++ apparently spells this as both _Alignof() and alignof() after 2011/03
>
> This is not correct.  C++ spells it alignof.  C spells it _Alignof, unless you include <stdalign.h>, in which case C spells it alignof and defines _ _alignof_is_defined.
>
> On FreeBSD, we define _Alignof in C++ mode, because it’s in the reserved identifier space and gives us something that works in C and C++.

So it is more broken than first appeared :-).  Extra spellings are a bug
since users don't know which one to use and prefer the worst one unless
they are experts in at least 3 versions of 3 standards (C-K&R, C90, C99,
C11, C++-mumble, gnu89, gnu99, gnu11) and FreeBSD variations on these.

There are also syntactical problems.  stdalign.h uses _Alignas and _Alignof,
but FreeBSD only defines _Alignas(x) and _Alignof(x).  The former is because
alignof is like sizeof so it doesn't need parentheses.  However,
alignof(typename) needs the parentheses and 'alignof expression' is 
apparently only a gnu extension, so it is difficult to construct an
example of Standard code without the parentheses.

_Alignas is more broken than _Alignof.  In the C case, _Alignas(x) is as
__aligned(x), but this only works if x is an expression.  __aligned(x)
is often used in FreeBSD code, but the same code in C++ with __aligned(x)
replaced by alignas(x) with any spelling is a syntax error.

Bruce


More information about the svn-src-head mailing list