svn commit: r348847 - head/sys/sys

Bruce Evans brde at optusnet.com.au
Mon Jun 10 16:17:04 UTC 2019


On Mon, 10 Jun 2019, Ian Lepore wrote:

> On Mon, 2019-06-10 at 07:49 -0600, Warner Losh wrote:
>> On Mon, Jun 10, 2019, 7:44 AM Conrad Meyer <cem at freebsd.org> wrote:
>>
>>> On Mon, Jun 10, 2019 at 2:10 AM Tijl Coosemans <tijl at freebsd.org>
>>> wrote:
>>>> On Mon, 10 Jun 2019 05:28:04 +0000 (UTC) Dmitry Chagin
>>>> <dchagin at FreeBSD.org> wrote:
>>>>> ...
>>>>> URL: https://svnweb.freebsd.org/changeset/base/348847
>>>>> Log:
>>>>>   Use C11 anonymous unions.
>>>>>
>>>>> Modified: head/sys/sys/ucred.h
>>>>
>>>> ...
>>>>
>>>> Isn't this a userland header that should work with non-C11
>>>> compilers?
>>> ...
>>> Why would one expect userland headers to work with non-C11 (gnu89)
>>> compilers?
>> ...
>> Because those compilers can choose non c11 variants of the language?
>
> Do we promise that userland will compile with -std=c89?  I hope not.

Only headers and libraries should support -std=c89.  <sys/cdefs.h> has
lots of support for compilers and POSIX versions going back to K&R C,
and only the K&R parts are completely broken.

FreeBSD also has the c89 and c99 utilities.  These require c89 and c99
headers to work under FreeBSD.  c89 uses CFLAGS -std=iso9899:199409
-pedantic.  I don't see how a 1994 standard can be correct for c89,
but -pedantic here might avoid the bug that -std=cxx doesn't actually
gives standard cxx, especially for clang.  c99 uses -std=iso9899:1999
-pedantic.  So anonymous unions are correctly disallowed by both c89
and c99.

At least the following headers still compile with c89: sys/types.h,
stdio.h, stdlib.h, the old version of sys/ucred.h.

> Anonymous unions may be a c11 feature, but they're also available with
> -std=gnu99, which I think is how we compile userland.

That is only the default, only for for parts of userland controlled by us.
Non-FreeBSD makefiles get at most the POSIX CFLAGS (something like -O)
from sys.mk if they use FreeBSD make, and something similar using gmake.

> I think -std=gnu99 is how we should also compile the kernel, and I
> think Bruce has been trying to say that for several years (but I'm not
> sure, because the emails that seem to say so are always so full of
> semi-related extraneous material that it's hard to be sure what they're
> saying).

-std can be forced for kernel builds and other pure FreeBSD builds, but
then it should be the correct one.

bsd.sys.mk only directly supports the user selecting the following standards:
- c89 or c90
- c94 or c95 (the c89 utility gives -std=c94, not -std=c89)
- c99
- gnu99 (default)
Newer and more useful old standards like gnu89 are hard to select.  The
user must set the undocumented variable CSTD even to change the default to
c89/90/94/95.  Adding -std=whatever to CFLAGS only works if it happens to
be added after -std=${CSTD}.

Bruce


More information about the svn-src-head mailing list