Creating a va_list dynamically?

Joseph S. Myers jsm28@cam.ac.uk
Mon Oct 9 11:15:00 GMT 2000


On Mon, 9 Oct 2000, Kaveh R. Ghazi wrote:

> Is it possible to dynamically and portably create a va_list?

No.  But autogen includes a library libsnprintfv (GPL but not assigned to
the FSF) that might be applicable to do what you want, though the last
time I looked it didn't cover C99 features (and optimising printf("%zu\n",
sizeof(foo)) is perfectly reasonable in C99 mode).

> I'm trying to see if I can easily teach gcc to optimize e.g.
> 
>  > fprintf("%d %s", 5, "hello") -> fputs("5 hello")
> 
> What I'd like to do is, at compile time, take the tree structures
> representing 5 and "hello" and dynamically create a va_list out of
> them.  Then I'd pass the format arg and the va_list to vasprintf() and
> emit a call to fputs with the resulting string.
> 
> (If I can't use something like vasprintf, I'd have to rewrite a
> complete *printf parser.  Bleah.)

You already have the parser in check_format_info, it just needs extending
to handle output for the ISO C formats that have no dependence on the
locale or rounding modes and so are safe to optimize.

One thing I want to do at some point - if any form of -Wsecurity security
audit option is acceptable for GCC - is add support for checking sprintf
into fixed-length buffers and warning if it can't be proved that the
buffer is big enough.  That would go a step closer to making
check_format_info useful for outputting format results for constant
arguments.

-- 
Joseph S. Myers
jsm28@cam.ac.uk



More information about the Gcc mailing list