As you said, either make the buffer static within the function and return a const char*
inline const char* pascalsToMillibars(uint32_t pascals) {
const size_t MBAR_STRLEN = 15;
static char str[MBAR_STRLEN];
snprintf (str, MBAR_STRLEN, "%4lu.%02lu mbar", pascals / 100ul, pascals % 100ul);
return str;
}
void setup() {
Serial.begin(115200); Serial.println();
Serial.println(pascalsToMillibars(101325ul));
}
void loop() {}
or as suggested, let the caller provide the buffer and be responsible for the memory
inline char* pascalsToMillibars(char* str, const size_t len, uint32_t pascals) {
snprintf (str, len, "%4lu.%02lu mbar", pascals / 100ul, pascals % 100ul);
return str;
}
void setup() {
const size_t MBAR_STRLEN = 15;
char str[MBAR_STRLEN];
Serial.begin(115200); Serial.println();
Serial.println(pascalsToMillibars(str, MBAR_STRLEN, 101325ul));
}
void loop() {}