This is the mail archive of the gcc-patches@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]
Other format: [Raw text]

Re: [PATCH] avoid using %lli et al.


On 01/04/2018 08:53 AM, Jakub Jelinek wrote:
On Thu, Jan 04, 2018 at 08:50:30AM -0700, Martin Sebor wrote:
On 01/04/2018 01:30 AM, Jakub Jelinek wrote:
On Wed, Jan 03, 2018 at 05:00:41PM -0700, Martin Sebor wrote:
This is an example where having a solution for bug 78014 would
be helpful.  I.e., a -Wformat checker to help enforce the use

No, because %zu isn't portable enough for all the hosts we support.

GCC could mitigate all these portability pitfalls by providing
its own versions of the functions (I suggested gcc_printf the
last time we discussed this subject).  libiberty already does
this for a small subset of the portability problems in some of
the standard functions (including vsprintf), so this would be
a natural extension of that approach.

Ugh, no.

	Jakub

I took me a while to process this well-articulated argument
but I think I finally got it.

An alternative to using %zu that I mentioned in my earlier
post is to cast the argument to the type the directive
expects:

> I.e., a -Wformat checker to help enforce the use ... (or
> an explicit cast from size_t) even on targets size_t is
> unsigned or unsigned long, respectively.

If providing interfaces to make portability to non-C99 hosts
easier is not palatable for some unknown reason, then -Wformat
could be enhanced to warn for uses of %zu and other similar
conversions to help prevent introducing them into GCC sources
regardless of the host GCC is being developed on.

The common idea of all of these solutions is to enhance our
tools and APIs to make it easier to avoid regressions like
the one you so kindly (and quickly) fixed for me.  But if
you prefer to spend your time and energy cleaning up the
mistakes of others rather than focus on adding improvements
then I understand if you don't agree with these suggestions.

Martin


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