[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [avr-gcc-list] printf "%*s" format
From: |
Erik Christiansen |
Subject: |
Re: [avr-gcc-list] printf "%*s" format |
Date: |
Wed, 18 Oct 2017 16:57:09 +1100 |
User-agent: |
Mutt/1.8.0 (2017-02-23) |
Reply-To: address@hidden
On 03.07.16 13:52, 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.
> Neither the documentation nor the implementation in vfprintf.c seem to
> mention it.
On 17.10.17 20:37, Paul "LeoNerd" Evans wrote:
> On Sun, 3 Jul 2016 13:52:08 +0100
> "Paul \"LeoNerd\" Evans" <address@hidden> wrote:
>
> > 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.
>
> Any response at all on this issue? Is this even the right mailing list
> to ask?
>
> I once again have run into a situation that would make use of it so I'm
> keen to find out if we can get this added...
My thoughts are:
o /usr/lib/avr/include/stdio.h warns that features have been
deliberately omitted in order to maintain the greater benefit of
small size. The lack of enthusiasm on the list suggests that the
smaller size is still preferred.
o My only 'C' books are from 1978 and 1988, and I'm having trouble
correlating your attempt to place control outside the control
string, in the form of a non-output variable in the variable list.
o It would seem to be infinitely simpler to merely null terminate
the string in buf, and use "%s", instead of adding unnecessary
user complexity and increasing code size. (Assuming it is 'C'.)
o The null terminated string for printf could be generated as you
show, using snprintf, which appears to be available.
If that is done, the problem ceases to exist.
Erik