[RFC] Make _FILE_OFFSET_BITS=64 default.
Paul Eggert
eggert@cs.ucla.edu
Thu Mar 20 01:17:00 GMT 2014
Joseph S. Myers wrote:
> I certainly don't think they should be overriding _Static_assert provided by GCC (>= 4.6)
Good point, thanks. Revised patches attached.
> I don't think the installed glibc headers should be providing _Static_assert
It's what FreeBSD <sys/cdefs.h> does, and applications seem to be doing
fine there. So there's good precedent, it's not risky, and it would
improve compatibility with FreeBSD.
> arguably assert.h should try to do something for the case
> of _ISOC11_SOURCE, non-C11 compiler
That wouldn't support one of the main attractions of _Static_assert,
namely that it works even when <assert.h> isn't included. Application
writers will prefer this feature, and defining _Static_assert in cdefs.h
gets us close enough to this goal to be reasonably useful in apps
compiled with pre-C11 compilers.
> generally that applies to any compiler possibly providing
> _Static_assert outside C11 mode - the library shouldn't get in the way of
> the user using the compiler feature
In general that's a good principle, but here there's not much to get in
the way of, as the glibc substitute does the job even when it takes over
from Clang etc. If there's consensus I could add the usual forest of
#ifs so as to not #define _Static_assert in non-GCC pre-C11 compilers
where _Static_assert is known to work, but that's not what we've done in
similar situations elsewhere in glibc, and there is some virtue in
simplicity.
-------------- next part --------------
From 45c96ea279e95aa499856f9062f743665fd564ee Mon Sep 17 00:00:00 2001
From: Paul Eggert <eggert@cs.ucla.edu>
Date: Wed, 19 Mar 2014 10:59:31 -0700
Subject: [PATCH 1/2] Approximate _Static_assert for pre-C11 compilers.
* misc/sys/cdefs.h (_Static_assert) [__STDC_VERSION__ < 201112L]:
New macro, for convenience with pre-C11 compilers.
---
ChangeLog | 6 ++++++
misc/sys/cdefs.h | 7 +++++++
2 files changed, 13 insertions(+)
diff --git a/ChangeLog b/ChangeLog
index f48f6bb..3d4c88d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2014-03-19 Paul Eggert <eggert@cs.ucla.edu>
+
+ Approximate _Static_assert for pre-C11 compilers.
+ * misc/sys/cdefs.h (_Static_assert) [__STDC_VERSION__ < 201112L]:
+ New macro, for convenience with pre-C11 compilers.
+
2014-03-19 Joseph Myers <joseph@codesourcery.com>
* math/libm-test.inc (fdim_test): Use ALL_RM_TEST.
diff --git a/misc/sys/cdefs.h b/misc/sys/cdefs.h
index 4d958ea..9402520 100644
--- a/misc/sys/cdefs.h
+++ b/misc/sys/cdefs.h
@@ -382,6 +382,13 @@
# define __glibc_likely(cond) (cond)
#endif
+#if ! (defined _Static_assert \
+ || (defined __STDC_VERSION__ && 201112L <= __STDC_VERSION__) \
+ || (__GNUC_PREREQ (4, 6) && !defined __STRICT_ANSI__))
+# define _Static_assert(e, s) extern int (*__glibc_Static_assert (void)) \
+ [sizeof (struct { unsigned int _Static_assert_failure: (e) ? 1 : -1; })]
+#endif
+
#include <bits/wordsize.h>
#if defined __LONG_DOUBLE_MATH_OPTIONAL && defined __NO_LONG_DOUBLE_MATH
--
1.8.5.3
-------------- next part --------------
From 8a8a42c8921f39e45fdcc43a7cc93f9cf6c35562 Mon Sep 17 00:00:00 2001
From: Paul Eggert <eggert@cs.ucla.edu>
Date: Wed, 19 Mar 2014 11:01:42 -0700
Subject: [PATCH 2/2] fts: allow _FILE_OFFSET_BITS=64 on 64-bit hosts
* io/fts.h: Use _Static_assert to check for _FILE_OFFSET_BITS problem,
so that we don't unnecessarily reject compilations with
_FILE_OFFSET_BITS=64 on 64-bit hosts.
---
ChangeLog | 5 +++++
io/fts.h | 8 +++++---
2 files changed, 10 insertions(+), 3 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 3d4c88d..834a973 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,10 @@
2014-03-19 Paul Eggert <eggert@cs.ucla.edu>
+ fts: allow _FILE_OFFSET_BITS=64 on 64-bit hosts
+ * io/fts.h: Use _Static_assert to check for _FILE_OFFSET_BITS problem,
+ so that we don't unnecessarily reject compilations with
+ _FILE_OFFSET_BITS=64 on 64-bit hosts.
+
Approximate _Static_assert for pre-C11 compilers.
* misc/sys/cdefs.h (_Static_assert) [__STDC_VERSION__ < 201112L]:
New macro, for convenience with pre-C11 compilers.
diff --git a/io/fts.h b/io/fts.h
index 0a070ba..f71f550 100644
--- a/io/fts.h
+++ b/io/fts.h
@@ -35,10 +35,12 @@
#include <features.h>
#include <sys/types.h>
-/* The fts interface is incompatible with the LFS interface which
- transparently uses the 64-bit file access functions. */
+/* When off_t is not 64 bits, the fts interface is incompatible with
+ the LFS interface which transparently uses the 64-bit file access
+ functions. */
#ifdef __USE_FILE_OFFSET64
-# error "<fts.h> cannot be used with -D_FILE_OFFSET_BITS==64"
+_Static_assert (sizeof (__off_t) == sizeof (__off64_t),
+ "<fts.h> cannot be used with 64-bit off_t on this platform");
#endif
--
1.8.5.3
More information about the Libc-alpha
mailing list