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]
Other format: [Raw text]

Re: use of %n in genmodes.c causes trouble on Vista


> According to my manpage, printf returns 0 on success, 1 on failure. No
> mention of the number of characters written. This is different with
> sprintf/snprintf (see e.g
> http://www.opengroup.org/onlinepubs/000095399/functions/snprintf.html),
> but IIRC a number of platforms don't implement those according to the
> standard anyway.

According to the page you cite, printf and fprintf "shall return the
number of bytes transmitted".  When Olivier first suggested this, my
original thought was the same as yours because I remembered the huge
mess in the VAX days with sprintf (does it return int or char *?), but
I've looked at lots of man pages (including ancient ones) and can't find
anything that says anything else about the return of printf.

> I suppose that the most portable way to achieve what you want here is
> to write to a temporary string, then compare the lengths of the
> temporary strings...

Agreed.

> Or just add a call to _set_printf_count_output in the relevant
> place, since AFAIK %n is still a standard-mandated printf format
> flag.

Where is the "relevant place"?  This would be a really messy host-dependent
call and I think it far better to eliminate the usage in *some* way than
to do this.


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