]> git.ipfire.org Git - thirdparty/lldpd.git/commitdiff
marshal: use __alignof__ operator if available
authorVincent Bernat <bernat@luffy.cx>
Sat, 23 Nov 2013 09:03:42 +0000 (10:03 +0100)
committerVincent Bernat <bernat@luffy.cx>
Sat, 23 Nov 2013 09:05:48 +0000 (10:05 +0100)
configure.ac
m4/alignof.m4 [new file with mode: 0644]
src/marshal.c

index 1e409e144008d087d1912db3ec3a6e63b6f68d26..9e1ac0ef887387a25ea20c0289bb6ea9aa85a7fe 100644 (file)
@@ -93,6 +93,7 @@ AC_CACHE_SAVE
 
 # Checks for typedefs, structures, and compiler characteristics.
 lldp_CHECK___PROGNAME
+lldp_CHECK_ALIGNOF
 
 # Checks for library functions.
 AC_CONFIG_LIBOBJ_DIR([src/compat])
diff --git a/m4/alignof.m4 b/m4/alignof.m4
new file mode 100644 (file)
index 0000000..f45caae
--- /dev/null
@@ -0,0 +1,14 @@
+#
+# lldp_CHECK_ALIGNOF
+#
+AC_DEFUN([lldp_CHECK_ALIGNOF],[
+  AC_CACHE_CHECK([whether compiler understands __alignof__], lldp_cv_check_alignof, [
+    AC_TRY_COMPILE([],
+       [ return __alignof__(long); ],
+       [ lldp_cv_check_alignof="yes" ],
+       [ lldp_cv_check_alignof="no" ])
+  ])
+  if test x"$lldp_cv_check_alignof" = x"yes"; then
+     AC_DEFINE([HAVE_ALIGNOF], [1], [Define if __alignof__ operator is available])
+  fi
+])
index 45c46cbcae004a5a109cdf5a14b9e1b2df2131b4..8a57d30528421462d1eeb5446adf88dd9a6227b5 100644 (file)
 #include "lldpd-structs.h"
 
 /* Stolen from CCAN */
-#define ALIGNOF(t) ((sizeof(t) > 1)?((char *)(&((struct { char c; t _h; } *)0)->_h) - (char *)0):1)
+#if HAVE_ALIGNOF
+# define ALIGNOF(t) (__alignof__(t))
+#else
+# define ALIGNOF(t) ((sizeof(t) > 1)?((char *)(&((struct { char c; t _h; } *)0)->_h) - (char *)0):1)
+#endif
 
 /* A serialized object */
 struct marshal_serialized {