avr-libc-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [avr-libc-dev] Implementing the vprintf "%*s" and "%.*s" formats


From: David Brown
Subject: Re: [avr-libc-dev] Implementing the vprintf "%*s" and "%.*s" formats
Date: Wed, 18 Oct 2017 10:05:25 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.2.0

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

It seems reasonable to me.  It is probably not a heavily used feature
in printf, but it is part of the standards and its absence could be
surprising to people.

David


On 17/10/17 22:10, Paul "LeoNerd" Evans wrote:
> 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. It is documented that
> 
> The variable width or precision field (an asterisk * symbol) is
> not realized and will to abort the output.
> 
> But it's unclear from this whether the absence is deliberate, or
> simply not implemented yet.
> 
> Would folk be amenable to a patch to add this feature? I have an 
> (as-yet untested) attempt at it it. I don't think it would
> massively increase code size, and it doesn't consume any more RAM
> at runtime.
> 
> But I thought I'd ask, in case there's some specific reason for
> its absence.
> 
> -----
> 
> === modified file 'libc/stdio/vfprintf.c' --- libc/stdio/vfprintf.c
> 2017-10-17 19:56:22 +0000 +++ libc/stdio/vfprintf.c   2017-10-17
> 19:57:23 +0000 @@ -344,6 +344,12 @@ flags |= FL_WIDTH; continue; } 
> +             if (c == '*') { +                   if (flags & FL_PREC) +      
>                 prec =
> va_arg(ap, int); +                else +                      width = 
> va_arg(ap, int); +              } if
> (c == '.') { if (flags & FL_PREC) goto ret;
> 
> 
> 
> 
> _______________________________________________ AVR-libc-dev
> mailing list address@hidden 
> https://lists.nongnu.org/mailman/listinfo/avr-libc-dev
> 

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (GNU/Linux)

iQEcBAEBAgAGBQJZ5wtFAAoJEPy4fZ5YP6apSzoH/iCKARNwbhhOhlJlR/H/00Px
PzJAgXdCAnylkKdg68J1gAcE2sSon4x1tE3zZKSKPs0rTWwJVSfTIq/Lx1fHp8SB
qR+u22yS5uwwwNX8W2goOfqsCLD54CPFVufmkKFSkPJXFQdgdQBVei/T+Xf/FYkn
xpMeQ0tCDpHehEiMIy7C5zOsUuVz9y9eFXjat0C6DkL0Nd3yyDUYJ7cHA+RZxzwE
mgMi6+FTOWAZRSlW5FeYWDNYHZ2FnXp4CGzkOHm0dRkMiD8vZFOWbJIHlT2u1XjJ
EkDZHy8ZsP4Pt3UOidmtOFcEtf4I0TjRrCNDJ0+9M3I/bPftQj2mv7bHHc4rGJQ=
=TMfS
-----END PGP SIGNATURE-----



reply via email to

[Prev in Thread] Current Thread [Next in Thread]