+
+AC_DEFUN([GRAS_CHECK_STRUCT_COMPACTION],
+[ AC_MSG_CHECKING(whether the struct gets packed)
+ AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include "confdefs.h"
+ #include <sys/types.h>
+ #include <stddef.h> /* offsetof() */
+ struct s {char c; double d;};
+ ]],[[switch (0)
+ case 0:
+ case (sizeof(struct s) == sizeof(double)+sizeof(char)):;
+ ]])],[gras_struct_packed=yes],[gras_struct_packed="no (good)"])
+
+ AC_MSG_RESULT($gras_struct_packed)
+ if test x$gras_struct_packed = xyes ; then
+ AC_MSG_ERROR([GRAS does not support packed structures since it leads to nasty misalignments])
+ fi
+
+ AC_MSG_CHECKING(whether the struct gets compacted)
+ AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include "confdefs.h"
+ #include <sys/types.h>
+ #include <stddef.h> /* offsetof() */
+ struct s {double d; int i; char c;};
+ ]],[[switch (0)
+ case 0:
+ case (offsetof(struct s,c) == sizeof(double)+sizeof(int)):;
+ ]])],[gras_struct_compact=yes],[gras_struct_compact=no])
+
+ AC_MSG_RESULT($gras_struct_compact)
+
+ if test x$gras_struct_compact = xyes ; then
+ AC_DEFINE_UNQUOTED(GRAS_STRUCT_COMPACT, 1,
+ [Defined if structures are compacted when possible.
+
+ Consider this structure: struct s {double d; int i; char c;};
+
+ If it is allowed, the char is placed just after the int. If not,
+ it has to be on the 8 bytes boundary imposed by the double.
+ ])
+ AC_MSG_CHECKING(whether arrays in struct can straddle struct alignment boundaries)
+
+ AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include "confdefs.h"
+ #include <sys/types.h>
+ #include <stddef.h> /* offsetof() */
+ struct s { double d; int i; char c[6]; };
+ ]],[[switch (0)
+ case 0:
+ case (offsetof(struct s,c) == sizeof(double)+sizeof(int)):;
+ ]])],[gras_array_straddle_struct=yes],[gras_array_straddle_struct=no])
+
+ AC_MSG_RESULT($gras_array_straddle_struct)
+
+ if test x$gras_array_straddle_struct = xyes ; then
+ AC_DEFINE_UNQUOTED(GRAS_ARRAY_STRADDLE_STRUCT, 1,
+ [Defined if arrays in struct can straddle struct alignment boundaries])
+ else
+ AC_MSG_ERROR([GRAS can only work on either architecture not compacting structures, or allowing array fields to straddle alignment boundaries (yet)])
+ fi
+ fi
+
+ AC_MSG_CHECKING(for changing alignment boundary structures)
+ AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include "confdefs.h"
+ #include <sys/types.h>
+
+ struct s {int i;double d;};
+ ]],[[switch (0)
+ case 0:
+ case (sizeof(struct s) == sizeof(double)+sizeof(int)):;
+ ]])],[gras_struct_changing=yes],[gras_struct_changing=no])
+
+ AC_MSG_RESULT($gras_struct_changing)
+
+ if test x$gras_struct_changing = xyes ; then
+ AC_DEFINE_UNQUOTED(GRAS_STRUCT_CHANGING, 1,
+ [Defined if the alignment of structures can vary over fields.
+
+ Consider the following structure:
+ struct s {
+ int i;
+ double d;
+ };
+
+ On Solaris, sizeof(struct s)=16, ie all fields get aligned to the
+ biggest boundary (and this will not be defined). On Linux,
+ sizeof(struct s)=12 (and this will be defined).
+ ])
+ fi
+])
+# END OF GRAS CHECK STRUCT COMPACTION
+
+AC_DEFUN([GRAS_C_COMPACT_STRUCT],
+[ AC_MSG_CHECKING(whether the struct gets compacted)
+ AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include "confdefs.h"
+ #include <sys/types.h>
+ #include <stddef.h> /* offsetof() */
+ struct s {double d; int a; int b;};
+ ]],[[switch (0)
+ case 0:
+ case (offsetof(struct s,b) == sizeof(double)+sizeof(int)):;
+ ]])],[gras_compact_struct=yes],[gras_compact_struct=no])
+
+ AC_MSG_RESULT($gras_compact_struct)
+
+ if test x$gras_compact_struct = xyes ; then
+ AC_DEFINE_UNQUOTED(GRAS_COMPACT_STRUCT, 1,
+ [Defined if structures are compacted when possible])
+ fi
+])
+# END OF GRAS COMPACT STRUCT