Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 30 Apr 2013 02:22:00 +1000 (EST)
From:      Bruce Evans <brde@optusnet.com.au>
To:        Ed Schouten <ed@80386.nl>
Cc:        svn-src-head@freebsd.org, svn-src-all@freebsd.org, src-committers@freebsd.org, Eitan Adler <eadler@freebsd.org>, Bruce Evans <brde@optusnet.com.au>
Subject:   Re: svn commit: r250037 - head/bin/hostname
Message-ID:  <20130430013949.O1819@besplex.bde.org>
In-Reply-To: <CAJOYFBDm=L-Q8SpdZ7bU3SceA1zbfnuvrU7u_oGN3Es7zUSbKA@mail.gmail.com>
References:  <201304282252.r3SMqiHH009205@svn.freebsd.org> <20130429212227.R1043@besplex.bde.org> <CAJOYFBDm=L-Q8SpdZ7bU3SceA1zbfnuvrU7u_oGN3Es7zUSbKA@mail.gmail.com>

next in thread | previous in thread | raw e-mail | index | archive | help
On Mon, 29 Apr 2013, Ed Schouten wrote:

> 2013/4/29 Bruce Evans <brde@optusnet.com.au>:
>> - usr.bin/rlogin/rlogin.c has it in a gratuitously different form, as
>>   'static _Noreturn void        usage(void);'.  This is bogus since
>>   _Noreturn is a wrapper for a new C++ feature
>
> I hate to correct you here, but _Noreturn is not a wrapper for a new
> C++ feature, it's a keyword that's part of C11. See:

Yes, I misread the ifdef in sys/cdefs.h.  So it is a new C feature as
well as a new C++ feature.

> All C11 keywords can be implemented on top of GCC-specific constructs,
> with the exception of _Generic. I would strongly prefer it if we used
> these keywords over our FreeBSD-specific solutions.

That would mainly churn the source code, and still depend for portability
on FreeBSD #defining them in sys/cdefs.h.  Just with different spelling.

> If the only objection is the spelling of these keywords (underscores,
> uppercase, etc), be sure to:
>
> #include <stdalign.h> /* For alignas/alignof. */
> #include <stdnoreturn.h> /* For noreturn. */
> #include <threads.h> /* For thread_local. */

Ideally, new code would just use the new features.  Then it would need
includes to get the nicer spelling and not depend on FreeBSD features.
But it is easier to use the FreeBSD features.

I once hoped that the portability hacks in sys/cdefs.h (that is, the
whole file) would go away when C became standard.  Instead, it grew
many more.  It is now 7 times larger and many more than 7 times more
convoluted than in FreeBSD-1.  In FreeBSD-1, it only defined the
following macros:
     __BEGIN_DECLS, __CONCAT(), __END_DECLS, __P(), __STRING(), __dead,
     __pure, const, inline, signed, volatile
where only the last 4 are for corrupting Standard C keywords.

`noreturn' (case-insensitive) is now used 9 times in /usr/src/*bin (.c files):
- 4 times for hard-coded __attribute__(())
- 3 times in rlogin.c for _Noreturn.  I already pointed out some of the
   syntax problems with these.  They are unportable since they give syntax
   errors with some versions of gcc, while either __dead or __dead2 would
   not have these syntax errors when correctly placed.  I don't know if the
   C11 keyword can be placed almost anywhere like the attribute can be now.
   If not, then it would be impossible to replace all the __dead2's by it
   without changing the syntax, and then it would give syntax errors for the
   old compilers.
- 2 times for NORETURN comments after usage() in fstat.  These are just
   garbage.  They are because lint is too stupid to understand __dead2 or
   _Noreturn, so it needs a comment to tell it that usage() doesn't return.
   But the comment for this is NOTREACHED, not NORETURN.  NORETURN also
   misdescribes the situtation for human readers, since it is usage() that
   doesn't return and the code after it that is not reached.  I dislike
   even correct lint comments.  Telling the compiler than functions don't
   return has worked better than telling lint this for more than 20 years.

Bruce



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20130430013949.O1819>