I'd like to file a complaint /s

We tried __attribute__ format printf years ago in beta versions. It was pulled before a release because it's far too pedantic about 32 bit integers.
The main problem is both int and long are both 32 bits. To use this on Teensy 4.x, we need a way to suppress the warnings for things like Serial.printf("%d", (long)number)) and Serial.printf("%ld", (int)number)). If these cases give warnings, I'm not going to put it into the core library headers.
Hmm if it's turned off why am I still seeing those exact warnings sometimes?

Would it not be possible to change the newlib definitions of int32_t/uint32_t to int instead of long?
 
I'm still struggling to understand. Are you suggesting we should turn on this overly pedantic warning for everything inheriting from Print class, and then turn it off only for Serial?

That’s what I thought you were suggesting, that “Serial.printf” needs to have the warnings shut off. If not, and instead the requirement is that only the “%d” and “%ld” have their warnings changed (and “%x” and “%lx” too), regardless of the Print subclass, then I’m not sure that’s possible.

(In the ticket, you said, “I will only merge this if we can find a way for Serial.printf("%d", (long)number) and Serial.printf("%ld", (int)number) to avoid needless warnings.”, which was why I changed to just Serial. I see now that it’s not just Serial — the requirement is for numbers.)

I disagree that it’s an overly-pedantic warning, or that’s it’s even a pedantic one, given that “%d” means “int” and “%ld” means “long int”, etc. But, that’s my opinion and I won’t push. I hear your points that ease of development with the existing ecosystem trumps some other things sometimes, and that existing code sometimes uses “%d” instead of “PRId32”, etc. C++ can sometimes look a little odd and overly-verbose and tedious. I shall close the PR. Thanks for clarifying.
 
Last edited:
Hmm if it's turned off why am I still seeing those exact warnings sometimes?

Would it not be possible to change the newlib definitions of int32_t/uint32_t to int instead of long?

@jmarsh is this when you use one of the system “printf” functions or a Print:: printf function? (That extra space is there because I’m not completely clear on how to turn off those emojis. It looks like “Print::printf”.) The warnings are still there for the former.
 
Last edited:
If some way could be found to suppress the printf format warnings for same size integers, I would love to enable this in Print class. That's why we tried in the 1.54 betas. It really would be useful to have, if it didn't produce an obnoxious number of pedantic warnings on so much existing code.
 
@jmarsh is this when you use one of the system “printf” functions or a Print:: printf function? (That extra space is there because I’m not completely clear on how to turn off those emojis. It looks like “Print::printf”.) The warnings are still there for the former.
On double-checking it's a class printf method that forwards to ::printf(). And yes for the love of god, can we turn off the obnoxious auto smiley crap that the forum software inserts. It's a plague that haunts every forum dealing with c++ programming.
 
I was able to find a solution that works for most cases:
1. Make a base class that just contains a printf-with-attached-format-attribute. Just about the same as Print’s implementation.
2. Whenever I have a class that has Print as a direct or “eventual” ancestor (eg. via Stream, a superclass of Print), I use multiple inheritance to extend from that class as well.
3. Put a using MyNewClass::printf; somewhere in the public section of my class, to help the compiler disambiguate.
4. And voilà, printf is now format-checked when I call it via an instance of my class.

Note that this won’t work if an instance of my class is accessed via pointer-or-reference-to-Print and you call printf on that.

I put that latest change in the QNEthernet library, in the latest push, if you’d like to have a look.
 
Back
Top