[AC 21.5] ALIGNOF with C11/C++11
Jerry James <[email protected]> Mon, 20 Apr 2015 15:10:40 -0600
| Newsgroups | gmane.emacs.xemacs.patches |
|---|---|
| Message-ID | <CAHCOHQnVOPCx2zYEYZF+oSN5DquZ4ZcD_7UnNucv+hc0U06tFw@mail.gmail.com> |
APPROVE COMMIT 21.5 On Fri, Apr 17, 2015 at 2:48 PM, Jerry James <[email protected]> wrote: > PATCH 21.5 > > Using gcc 5.0, the build fails with both -std=c11 and -std=c++11, > because of a clash on the name max_align_t. But we don't need to > define max_align_t in those 2 cases, because the languages themselves > now define operators that can be used for ALIGNOF, as in this patch. I tweaked the logic slightly, so I am actually committing this patch: diff -r d3d073aceaea src/ChangeLog --- a/src/ChangeLog Sat Apr 18 23:10:40 2015 +0100 +++ b/src/ChangeLog Mon Apr 20 15:07:44 2015 -0600 @@ -1,3 +1,9 @@ +2015-04-20 Jerry James <[email protected]> + + * lisp.h (max_align_t): Do not define if C11 or C++11, or a later + version of either, is in use. + (ALIGNOF): Define with native operators in C11 and C++11 and later. + 2015-04-18 Aidan Kehoe <[email protected]> * sequence.c (Fclear_string): New, API from GNU. Zero a string's diff -r d3d073aceaea src/lisp.h --- a/src/lisp.h Sat Apr 18 23:10:40 2015 +0100 +++ b/src/lisp.h Mon Apr 20 15:07:44 2015 -0600 @@ -1154,6 +1154,8 @@ /* ------------------------ alignment definitions ------------------- */ +#if (!defined (__STDC_VERSION__) || __STDC_VERSION__ < 201112L) && \ + (!defined (__cplusplus) || __cplusplus < 201103L) /* No type has a greater alignment requirement than max_align_t. (except perhaps for types we don't use, like long double) */ typedef union @@ -1163,6 +1165,7 @@ struct { void (*f)(void); } f; struct { double d; } d; } max_align_t; +#endif /* ALIGNOF returns the required alignment of a type -- i.e. a value such that data of this type must begin at a memory address which is a @@ -1170,7 +1173,11 @@ as the type itself. */ #ifndef ALIGNOF -# if defined (__GNUC__) && (__GNUC__ >= 2) +# if defined (__STDC_VERSION__) && __STDC_VERSION__ >= 201112L +# define ALIGNOF(type) _Alignof(type) +# elif defined (__cplusplus) && __cplusplus >= 201103L +# define ALIGNOF(type) alignof(type) +# elif defined (__GNUC__) && (__GNUC__ >= 2) /* gcc has an extension that gives us exactly what we want. */ # define ALIGNOF(type) __alignof__ (type) # elif ! defined (__cplusplus) -- Jerry James http://www.jamezone.org/