changeset 17781:0885e560f726

obstack: prefer alignof to calculating alignments by hand * lib/obstack.c: Include <stdalign.h>. (struct fooalign): Remove. (DEFAULT_ALIGNMENT): Use alignof rather than the old offsetof hack. * modules/obstack (Depends-on): Add stdalign.
author Paul Eggert <eggert@cs.ucla.edu>
date Wed, 29 Oct 2014 00:22:08 -0700
parents 4fbd46593c56
children f6c039e09a3b
files ChangeLog lib/obstack.c modules/obstack
diffstat 3 files changed, 11 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2014-10-29  Paul Eggert  <eggert@cs.ucla.edu>
+
+	obstack: prefer alignof to calculating alignments by hand
+	* lib/obstack.c: Include <stdalign.h>.
+	(struct fooalign): Remove.
+	(DEFAULT_ALIGNMENT): Use alignof rather than the old offsetof hack.
+	* modules/obstack (Depends-on): Add stdalign.
+
 2014-10-28  Paul Eggert  <eggert@cs.ucla.edu>
 
 	obstack: use size_t alignments and check for overflow
--- a/lib/obstack.c
+++ b/lib/obstack.c
@@ -48,6 +48,7 @@
 #endif
 
 #ifndef _OBSTACK_ELIDE_CODE
+# include <stdalign.h>
 # include <stdlib.h>
 # include <stdint.h>
 
@@ -58,17 +59,12 @@
   long double d;
   void *p;
 };
-struct fooalign
-{
-  char c;
-  union fooround u;
-};
 /* If malloc were really smart, it would round addresses to DEFAULT_ALIGNMENT.
    But in fact it might be less smart and round addresses to as much as
    DEFAULT_ROUNDING.  So we prepare for it to do that.  */
 enum
 {
-  DEFAULT_ALIGNMENT = offsetof (struct fooalign, u),
+  DEFAULT_ALIGNMENT = alignof (union fooround),
   DEFAULT_ROUNDING = sizeof (union fooround)
 };
 
--- a/modules/obstack
+++ b/modules/obstack
@@ -8,6 +8,7 @@
 Depends-on:
 gettext-h
 exitfail
+stdalign
 stdint
 stdlib