I don't know that library, but have you tried this?
Serial.printf("%s", "Hello longer world");My default expectation is that it is a footgun that I do not understand.
The alternative is that I've stumbled across a very rare bug in some popular libraries, or else my hardware is cursed in a very specific and reproducible way.
IIRC, some string implementations have separate implementations for very short strings vs. longer ones. Similar thing for vectors.
I also see some size-related logic in the (current?) String implementation [0] [1].
String is a class with no virtual methods, and its first data member is a pointer to the underlying buffer [2]. So if Stream.printf unintentionally type-puns String to char*, it might work out okay?
[0] https://github.com/arduino/ArduinoCore-API/blob/master/api/S...
[1] https://github.com/arduino/ArduinoCore-API/blob/master/api/S...
[2] https://github.com/arduino/ArduinoCore-API/blob/cb3ab4c90d71...
So basically the foot-gun is that smaller String()s appear to work "by accident".
[0] https://arduino.stackexchange.com/a/90332
[1] https://github.com/espressif/arduino-esp32/blob/7a82915de215...
You're only printing 4 bytes because your string is sufficiently short, and the next byte it's reading is 0, since your capacity is small.
If your string were about 17 million bytes long (0x0101'0101 == 16843009 is the first value that causes problems), then your address, capacity, and size would all likely be nonzero, in which case your Arduino would just keep printing bytes until it lucked upon a zero, or overran its buffer so badly that it started trying to read different segments of memory and eventually segfaulted.
I don't think I've ever used an arduino core for something that had an MMU. It should happily keep printing all the way until the end of memory, and either stop there because it's zeros after, or wrap back to the start depending on the board. I have written code to dump out every byte in memory over serial before, just for kicks.
Serial.printf("%s", String("Hello world...").c_str());
I actually don't see a "Serial.printf(...)" method in these docs [1], but I do see it here [2]. I'm not sure I'm looking at that right docs for your library though.[0] https://www.arduino.cc/reference/en/language/variables/data-...
[1] https://www.arduino.cc/reference/en/language/functions/commu...
[2] https://docs.particle.io/reference/device-os/api/serial/prin...
> I actually don't see a "Serial.printf(...)" method
I think it's coming from the ESP32-specific libraries. Some cursory searching didn't find the spot, but it may be some magical preprocessor directive stuff.
[0] https://github.com/espressif/arduino-esp32/blob/7a82915de215...
in my experience it's not to do with code. your serial/usb runs the bytes back through your debugger (typically IDE On the PC). Your IDE has config settings like baud rate +/- encoding that you have to config. If that IDE config is messed up (IDE Is presumably printing out your printf bytes over usb or whatever), then your output is bytes. Make sure your baud is correct.
In a C++ library you would probably make the format function type safe. But both Clang and gcc have annotations you can add to functions using format strings so they are type-checked
The C-language varargs concept and the C++ object model are not compatible. C++ provides varargs only for backwards compatibility with legacy C libraries. New APIs written in C++ should not be using it because passing a C++ object through it is undefined behaviour. No amount of rationalizing (as all the comments downthread are doing) is of any value: undefined behavior is undefined.
Clang at least errors out here.
C++ is a mess.
It sounds more like a crappy library designed by people who don't know their craft. It's easier to blame the tools.
I was having this conversation with someone the other day regarding GenAI. The expectations for understanding the lowest-level concerns have changed generationally. Today's hardware wizard might prize their old-school understanding of fundamentals but would probably be rubbish in 1948.
Anecdote: I've got a couple languages and decades under my belt, and a very simple C/C++ Arduino project is making me doubt my sanity. Ex:
________________________EDIT: To save readers some time--I didn't intend to nerd-snipe [0] y'all, honest!--the answer has been found, and it is probably:
The shorter payloads like "Hello World" happen to give the desired results only as an accident of optimization code.[0] https://xkcd.com/356/