Mercurial > hg > xemacs-beta
diff src/lisp.h @ 454:d7a9135ec789 r21-2-42
Import from CVS: tag r21-2-42
author | cvs |
---|---|
date | Mon, 13 Aug 2007 11:40:54 +0200 |
parents | 3d3049ae1304 |
children | e7ef97881643 |
line wrap: on
line diff
--- a/src/lisp.h Mon Aug 13 11:40:23 2007 +0200 +++ b/src/lisp.h Mon Aug 13 11:40:54 2007 +0200 @@ -193,20 +193,45 @@ # endif /* GNUC */ #endif +/* No type has a greater alignment requirement than max_align_t. + (except perhaps for types we don't use, like long double) */ +typedef union +{ + struct { long l; } l; + struct { void *p; } p; + struct { void (*f)(void); } f; + struct { double d; } d; +} max_align_t; + #ifndef ALIGNOF # if defined (__GNUC__) && (__GNUC__ >= 2) -# define ALIGNOF(x) __alignof__ (x) +/* gcc has an extension that gives us exactly what we want. */ +# define ALIGNOF(type) __alignof__ (type) +# elif ! defined (__cplusplus) +/* The following is mostly portable, except that: + - it doesn't work for inside out declarations like void (*) (void). + (so just call ALIGNOF with a typedef'ed name) + - it doesn't work with C++. The C++ committee has decided, + in its infinite wisdom, that: + "Types must be declared in declarations, not in expressions." */ +# define ALIGNOF(type) offsetof (struct { char c; type member; }, member) # else -# define ALIGNOF(x) sizeof (x) +/* The following should be completely portable, but might give values + that are larger than necessary. But never larger than the maximum + possible alignment. */ +# define ALIGNOF(type) \ +((sizeof (type) % sizeof (max_align_t)) == 0 ? \ + sizeof (max_align_t) : \ + (sizeof (type) % sizeof (max_align_t))) # endif -#endif +#endif /* ALIGNOF */ #define ALIGN_SIZE(len, unit) \ ((((len) + (unit) - 1) / (unit)) * (unit)) /* #### Yuck, this is kind of evil */ #define ALIGN_PTR(ptr, unit) \ - ((void *) ALIGN_SIZE ((long) (ptr), unit)) + ((void *) ALIGN_SIZE ((size_t) (ptr), unit)) #ifndef DO_NOTHING #define DO_NOTHING do {} while (0)