Quantcast
Viewing all articles
Browse latest Browse all 5391

SDK • Re: troubletrouble defining a macro to replace a zero argument fn call: micros()

Cross-posted with 'arg001'
shouldn't %d handle a uint64_t?
Never has in my experience, whether compiling for a Pi or a Pico.

I believe this is because the "%d" indicates the value to be printed will be in a particular place on the stack when it won't actually be in that place, and you have to use a different "%lld" so it does know where it is. Or something like that.

You can use "printf("%" PRId64 "\n", num)" as an alternative to using "%lld" if you "#include <inttypes.h>".

Code:

#include <stdio.h>#include "pico/stdlib.h"int main(void) {    stdio_init_all();    while (!stdio_usb_connected()) {        sleep_ms(100);    }    while (true) {        uint64_t num = 1234567890987654321;        printf("%d"   "\n", num); // Fails        printf("%lld" "\n", num); // Works        sleep_ms(1000);        printf("\n");    }}

Code:

012345678909876543215369010841234567890987654321
If you add "target_compile_options(${PROJECT_NAME} PRIVATE -Wall -Werror)" to your 'CMakeLists.txt' that will show where the number formatting needs to change to make things work.

No idea how you would do the equivalent when using Arduino.

Statistics: Posted by hippy — Fri Nov 15, 2024 11:39 am



Viewing all articles
Browse latest Browse all 5391

Trending Articles