This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: `quad' printf format specifier ?


 > From: Marc Espie <Marc.Espie@liafa.jussieu.fr>
 > 
 > > 	Perhaps the right fix would be for the format check for %qd to
 > > stop examining whether the underlying type is long long, but instead
 > > it should check whether the type of the argument is `quad_t' at some
 > > level of abstraction.  I don't know if this info has been lost at the
 > > point of the test though.
 > 
 > I'm afraid it has been... IF you know how to patch gcc/egcs to make it
 > work at that level, this is VERY fine. Otherwise, we would want egcs
 > to stop assuming that quad_t == long long, since this is plain wrong.
 > 
 > If you prefer: we slightly prefer "%qd" to behave correctly in the
 > presence of (quad_t) than yield possible bogus warnings... the best
 > way would probably be to keep the type-info and ensure that quad_t has
 > been used (though there is a good chance that some code will roll its
 > own), but baring that, equating "%qd" with long long is more annoying
 > than anything.
 > -- 
 > 	Marc Espie		


	I don't think we have to worry about people who roll their own
quad_t.  Remember we're talking about format specifier checks for printf
from libc.  Thus the quad_t in user code must be the same one used when
the printf function from libc was built.  I.e. both must be whatever the
OS's notion of quad_t is.  If the user rolls their own, all bets are off. 

	As for the actual solution, the info is available.  If you look
at the end of function check_format_info() in c-common.c, all the tree
information is there for you.  All you have to do is check if the name
of the type is "quad_t" and make an exception for that case when the
format specifier is 'q'.  There is a problem when using layers of
typedefs.  E.g. 

 > typedef long quad_t; /* From OS header */
 > 
 > typedef quad_t q2; /* In user code */
 > printf("%qd", (q2) 0);

	In this case, when you muck through the tree structure, the
"type" appears to be "q2".  So I think what you need to do is chain
through the typedef declarations somehow (ending when you reach a
builtin type) to see if any of them are "quad_t" and if you find quad_t,
then make the exception.  I'm not an expert on trees so you'll have to
figure out how to do that yourself. 

		--Kaveh
--
Kaveh R. Ghazi			Engagement Manager / Project Services
ghazi@caip.rutgers.edu		Qwest Internet Solutions


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]