sentinel and printf check macros

Egbert Eich eich at suse.de
Wed Apr 27 08:29:06 PDT 2005


gcc-4 has checks for sentinels (terminating NULL in varargs lists)
and printf-like lists which can be controlled by attributes.

The sentinel check catches code that terminates a varargs list with
0 instead of NULL which causes problems on 64bit systems.
The printf check is useful to check a variable list against a format
string.
It would make sense to add these attributes to function declaration
in header files if the compiler supports them.
I therefore propose to add the following macros to include/Xfuncproto.h:

+#if defined(__GNUC__) && (__GNUC__ >= 4)
+# define _X_SENTINEL(x) __attribute__ ((__sentinel__(x)))
+# define _X_ATTRIBUTE_PRINTF(x,y) __attribute__((__format__(__printf__,x,y)))
+#else
+# define _X_SENTINEL(x)
+# define _X_ATTRIBUTE_PRINTF(x,y)
+#endif /* GNUC >= 4 */

Since Xfuncproto.h so far doesn't contain any compiler specific macro
definition this would be a new thing. 
I therefore post it here for discussion.

Any thoughts?

Cheers,
	Egbert.


More information about the xorg-arch mailing list