Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Printing a zero value uint64_t number fails. #1691

Closed
greiman opened this issue Sep 3, 2023 · 4 comments · Fixed by #1692
Closed

Printing a zero value uint64_t number fails. #1691

greiman opened this issue Sep 3, 2023 · 4 comments · Fixed by #1692

Comments

@greiman
Copy link

greiman commented Sep 3, 2023

Here is a test case:

void setup() {
  Serial.begin(9600);
  while (!Serial) {}
  uint64_t n = 123;
  uint64_t m = n;
  Serial.print("n - m = ");
  Serial.println(n - m);
  n++;
  Serial.print("n - m = ");
  Serial.println(n - m);
}
void loop() {}

The output is:

n - m =
n - m = 1

The problem is in printULLNumber here

I can see how zero fails but am not sure of the best fix.

Probably the while needs to be a do while loop.

@earlephilhower
Copy link
Owner

Can you give an MCVE? It works fine as far as I can tell:

void setup() {
}
uint64_t uz = 0;
void loop() {
    Serial.printf("%" PRIu64 "\n", uz);
    delay(500);
}

gives

0
0
0
...

@greiman
Copy link
Author

greiman commented Sep 3, 2023

Sorry, I accidentally hit comment too soon. see the above example.

@earlephilhower
Copy link
Owner

Ah, thanks. Arduino reinventing vfprintf and not actual printf which makes sense (the Serial.printf bit is handled by Newlib which I'm sure is good).

You might want to push this upstream to the main ArduinoCore-API repo since this is untouched Arduino.cc code.

@earlephilhower
Copy link
Owner

arduino/ArduinoCore-API#178

Already opened 9 months ago.

earlephilhower added a commit that referenced this issue Sep 3, 2023
Move to a patched ArduinoCore-API revision.

Fixes #1691
earlephilhower added a commit that referenced this issue Sep 3, 2023
Move to a patched ArduinoCore-API revision.

Fixes #1691
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants