printf "%*s" format

"Paul \"LeoNerd\" Evans" <[email protected]> Sun, 3 Jul 2016 13:52:08 +0100
Newsgroups gmane.comp.hardware.avr.gcc
Message-ID <[email protected]>
I often find it useful to be able to print a character buffer of
dynamically-known size by using some variant on

  printf("%.*s", len, buf);

It appears to me that avr-libc doesn't recognise this particular flag.
Neither the documentation nor the implementation in vfprintf.c seem to
mention it. If I try it, it just gives up. E.g.

  uint8_t len;
  uint8_t buf[16];
  ...
  printf("BUF=%d <%.*s>\n", len, len, buf);

I get output simply

  BUF=4 <

it stops parsing at the .*, and doesn't even get as far as printing the
'>' and trailing linefeed.

Would folk be amenable to a patch to add this feature? To my eye it
doesn't look like it would be more than about a 5-line change to add
it, I don't think it would massively increase code size.

But I thought I'd ask first, in case there's some specific reason for
its absence.

-- 
Paul "LeoNerd" Evans

[email protected]      |  https://metacpan.org/author/PEVANS
http://www.leonerd.org.uk/  |  https://www.tindie.com/stores/leonerd/

_______________________________________________
AVR-GCC-list mailing list
[email protected]
https://lists.nongnu.org/mailman/listinfo/avr-gcc-list
signature.asc (application/pgp-signature, 181 B)
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2

iEYEARECAAYFAld5CngACgkQvLS2TC8cBo1uQQCglATHJSda7W3JySUhANRTHkDs
sL8AoMbQDadBsxZcFFx2iCYfUNrgRxGw
=hZsO
-----END PGP SIGNATURE-----