This is the mail archive of the
mailing list for the newlib project.
Re: Divergence from BSD sources, e.g. __GNUC_PREREQ()
- From: Ralf Corsepius <ralf dot corsepius at rtems dot org>
- To: newlib at sourceware dot org
- Date: Thu, 04 Apr 2013 10:47:24 +0200
- Subject: Re: Divergence from BSD sources, e.g. __GNUC_PREREQ()
- References: <515D32D1 dot 7080804 at embedded-brains dot de>
On 04/04/2013 09:59 AM, Sebastian Huber wrote:
I have some questions about the divergence from BSD sources. The
background is that <sys/queue.h> is broken in Newlib since __offsetof()
is undefined. I wanted to update the file in Newlib with the latest
version from FreeBSD, but now some problems arise.
What is the purpose of <sys/cdefs.h> in Newlib?
Like the bsd version, it's an internal libc header, whose only purpose
is to provide some internal defines and not meant to be used in
This file seems to be
derived from BSD sources, but current BSD versions look quite
Correct, they were forked long time ago and now have diverged. That
said, though they have common origins, BSD actually isn't of actual
interest here and even less so FreeBSD-compatibility, IMO.
For example last year the new macro __GNUC_PREREQ() was
introduced in "libc/include/sys/features.h":
/* Macro to test version of GCC. Returns 0 for non-GCC or too old GCC. */
# if defined __GNUC__ && defined __GNUC_MINOR__
# define __GNUC_PREREQ(maj, min) \
((__GNUC__ << 16) + __GNUC_MINOR__ >= ((maj) << 16) + (min))
# define __GNUC_PREREQ(maj, min) 0
#endif /* __GNUC_PREREQ */
In FreeBSD we have a similar macro in <sys/cdefs.h>:
* Macro to test if we're using a specific version of gcc or later.
#if defined(__GNUC__) && !defined(__INTEL_COMPILER)
#define __GNUC_PREREQ__(ma, mi) \
(__GNUC__ > (ma) || __GNUC__ == (ma) && __GNUC_MINOR__ >= (mi))
#define __GNUC_PREREQ__(ma, mi) 0
Why don't we follow the BSD development more to simplify code re-use?
Please elaborate the bug in newlib this would fix. icc has never been of
interest to newlib, while __GNUC_PREREQ can't be removed without
introducing incompatibilities in newlib.
Also note that newlib's __GNUC_PREREQ and FreeBSD's __GNUC_PREREQ__ are
not interchangable (__GNUC_PREREQ can be used for version comparison,
__GNUC_PREREQ__ is binary).
The latest version of FreeBSD <sys/queue.h> uses __containerof():
IMO, this is a FreeBSD implementation detail, newlib may or may not
adopt for BSD compatibility.
That said, I am against adopting it, because "FreeBSD sys/queue.h" has a
history FreeBSD changing it ad-lib, which means any attempt to provide
FreeBSD compatibility will fail in longer terms.