]> granicus.if.org Git - strace/blobdiff - gcc_compat.h
netlink_sock_diag: print inet_diag_sockid.idiag_if as an interface index
[strace] / gcc_compat.h
index c06d3c1d0d0ca205d58d3e47c38752cfa30e57c9..956aff1767c48cf8dc4ab42f220499bb0bed8475 100644 (file)
@@ -1,5 +1,6 @@
 /*
  * Copyright (c) 2015 Dmitry V. Levin <ldv@altlinux.org>
+ * Copyright (c) 2015-2017 The strace developers.
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -25,8 +26,8 @@
  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-#ifndef GCC_COMPAT_H_
-#define GCC_COMPAT_H_
+#ifndef STRACE_GCC_COMPAT_H
+#define STRACE_GCC_COMPAT_H
 
 #if defined __GNUC__ && defined __GNUC_MINOR__
 # define GNUC_PREREQ(maj, min) \
 # define ATTRIBUTE_PACKED      /* empty */
 #endif
 
+#if GNUC_PREREQ(3, 0)
+# define SAME_TYPE(x, y)       __builtin_types_compatible_p(typeof(x), typeof(y))
+# define FAIL_BUILD_ON_ZERO(expr) (sizeof(int[-1 + 2 * !!(expr)]) * 0)
+/* &(a)[0] is a pointer and not an array, shouldn't be treated as the same */
+# define MUST_BE_ARRAY(a) FAIL_BUILD_ON_ZERO(!SAME_TYPE((a), &(a)[0]))
+#else
+# define SAME_TYPE(x, y)       0
+# define MUST_BE_ARRAY(a)      0
+#endif
+
 #if GNUC_PREREQ(3, 0)
 # define ATTRIBUTE_MALLOC      __attribute__((__malloc__))
 #else
 # define ATTRIBUTE_SENTINEL    /* empty */
 #endif
 
+#if GNUC_PREREQ(4, 1)
+# define ALIGNOF(t_)   __alignof__(t_)
+#else
+# define ALIGNOF(t_)   (sizeof(struct { char x_; t_ y_; }) - sizeof(t_))
+#endif
+
 #if GNUC_PREREQ(4, 3)
 # define ATTRIBUTE_ALLOC_SIZE(args)    __attribute__((__alloc_size__ args))
 #else
 # define ATTRIBUTE_ALLOC_SIZE(args)    /* empty */
 #endif
 
-#endif
+#endif /* !STRACE_GCC_COMPAT_H */