sentinel and printf check macros

Egbert Eich eich at suse.de
Fri Apr 29 01:01:36 PDT 2005


Roland Mainz writes:
 > Adam Jackson wrote:
 > > On Wednesday 27 April 2005 11:29, Egbert Eich wrote:
 > > > 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?
 > > 
 > > Xfuncproto.h is probably the logical place.  I was considering doing something
 > > similar in compiler.h but that's not visible from the clients.  Sounds good
 > > to me.
 > 
 > What about introducing a Xcompiler.h to handle all compiler-specific
 > optimisations there ?
 > 

Looking at Xfuncproto.h it seems it currently only contains some generic
defines for c++ wrappers, and various prototype defines. They seem to
be controlled by some command line defines that are generated by imake.
Imake can itself check for the compiler version - at least in the gcc 
case - It is one of the few things it does. 
Adding specific tests for a compiler and its version to the X headers 
would be a new thing. On the other hand these attributes are very compiler
dependent and there is probably no way to handle this in a generic manner.

DDX compiler.h is hidden from 'the general public' for good reasons.
Right now the introduction of a Xcompiler.h would be overkill im my
eyes as it would have to be included similarly as Xfuncproto.h.

I don't see a reason for doing this at this time. We may want to reconsider
this in the future. 
I just would like to know if - also in the light of our autotooling effords -
adding compiler specific tests to the headers would be acceptable.

Cheers,
	Egbert.




More information about the xorg-arch mailing list