This is the mail archive of the gdb-patches@sources.redhat.com mailing list for the GDB project.


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

Re: [fyi] fix mips-tdep.c -Wprintf(a?"%d":"%d%d", ...)


Eli Zaretskii wrote:
> 
> On Tue, 20 Feb 2001, Andrew Cagney wrote:
> 
> > I've checked in the attatched.  A GCC variant didn't like conditional
> > formats vis:
> >
> >       printf (cond ? "arg1=%d" : "arg1=%d arg2+%d", arg1, arg2);
> 
> That's one of my gripes with latest versions of GCC (which version did
> you use, btw?): this change caused lots of valid C code to start
> emitting tons of warnings.  Ulrich Drepper tried to change GCC
> maintainers' minds on this one (evidently, glibc uses such expressions
> in printf's), to no avail IIRC.
> 
> Isn't there a compiler switch to turn this warning off?  Perhaps we
> should use it instead of ``fixing'' that which isn't broken.

	ac131313@localhost$ gcc --version
	egcs-1.1.2

but I know it is lieing - there should be a ``+ NetBSD patches''
appended.

The warning comes from the ``-Wprintf'' flag so I think fixing this
little nuance is far less of a hassle than dropping -Wprintf.  (To be
honest, I personally don't like the ``?:'' operator - I can't debug it -
so I don't object to this ``fix'' :-).

The other thing to keep in mind is that the ui_out interface strongly
discourages the above convention.  What was:

>       printf (cond ? "arg1=%d" : "arg1=%d arg2+%d", arg1, arg2);

and I rewrote to something like:

	printf ("arg1=");
	printf ("%d", arg1);
	if (cond)
	  {
	     printf (" arg2+");
	     printf ("%d", arg2);
	  }

will eventually be written as something like:

	ui_out_text ("arg1=");
	ui_out_int (arg1, fmt, "arg1");
	if (cond)
	  {
	     ui_out_text (" arg2+");
	     ui_out_int (arg2, fmt, "arg2");
	  }

so I'm in a way just helping the code along a little :-)

	enjoy,
		Andrew


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