printf "%*s" format

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

printf "%*s" format

Paul "LeoNerd" Evans
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

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

_______________________________________________
AVR-GCC-list mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/avr-gcc-list

attachment0 (188 bytes) Download Attachment
Loading...