Printf %S printing from PROGMEM not functional, compiler error

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Printf %S printing from PROGMEM not functional, compiler error

NicoHood
The avr printf docs[0] say:
"S Similar to the s format, except the pointer is expected to point to a
program-memory (ROM) string instead of a RAM string."


Now I try to:
const char* PROGMEM name;
printf("%S:%lu\n", name, i);

But I get the following compiler error:
error: format '%S' expects argument of type 'wchar_t*', but argument 2
has type 'const char*' [-Werror=format=]
printf("%S:%u\n", name, i);

The reason is possibly because the "normal" libc prints wide characters
here. The question to me is how to print PROGMEM strings, as written in
the docs.

And "just for fun" I would like to know how to print wide characters, if
%S gets overwritten by this PROGMEM option. I might need to use this in
the future, but it seems incompatibel then!?

I am using avrlibc 2.0.0 with avr-gcc 7.3.0 on Arch Linux.

~Nico

[0]:
https://www.nongnu.org/avr-libc/user-manual/group__avr__stdio.html#gaa3b98c0d17b35642c0f3e4649092b9f1

_______________________________________________
AVR-libc-dev mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/avr-libc-dev
Reply | Threaded
Open this post in threaded view
|

Re: Printf %S printing from PROGMEM not functional, compiler error

Joerg Wunsch
As [hidden email] wrote:

> But I get the following compiler error:
> error: format '%S' expects argument of type 'wchar_t*', but argument 2
> has type 'const char*' [-Werror=format=]
> printf("%S:%u\n", name, i);

Then do as suggested, and turn off compiler warnings (and -Werror) for
this.

> And "just for fun" I would like to know how to print wide characters

You can't.  avr-libc doesn't implement wide chars in any way.
--
cheers, Joerg               .-.-.   --... ...--   -.. .  DL8DTL

http://www.sax.de/~joerg/
Never trust an operating system you don't have sources for. ;-)

_______________________________________________
AVR-libc-dev mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/avr-libc-dev
Reply | Threaded
Open this post in threaded view
|

Re: Printf %S printing from PROGMEM not functional, compiler error

Joerg Wunsch
As Joerg Wunsch wrote:

> > But I get the following compiler error:
> > error: format '%S' expects argument of type 'wchar_t*', but argument 2
> > has type 'const char*' [-Werror=format=]
> > printf("%S:%u\n", name, i);
>
> Then do as suggested, and turn off compiler warnings (and -Werror) for
> this.

Sorry, I've been sick at the weekend, so my previous reply was a
little terse.

In general, the C standard reserves lowercase formatting letters for
future standardized conversions, but leaves other characters (so
namely uppercase letters) for "extensions".

Thus, avr-libc's use of %S for progmem strings is fully standards
compliant.  It's GCC here that applies wrong assumptions.  It would be
cool if we could somehow "tune" that in the avr-libc printf()
prototype (to avoid the pointless warning), but I'm not enough of a
GCC expert on that.

> > And "just for fun" I would like to know how to print wide characters
>
> You can't.  avr-libc doesn't implement wide chars in any way.

The standard's format specifier for a wide character string is "%ls".

That's why GCC's notion of %S is just another kind of an extension to
the standard only.  We've picked %S for progmem strings, since we
don't support wide characters anyway, and it seemed to be the most
logical extension.

--
cheers, Joerg               .-.-.   --... ...--   -.. .  DL8DTL

http://www.sax.de/~joerg/
Never trust an operating system you don't have sources for. ;-)

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