How to snprintf uint64_t?

Using WSL2, NCS 2, VSCode.

I tried to snprintf("%ull\n", (uint64_t)5) but I only see "ul" printed to the screen.

Here are the relevant prj.conf values

CONFIG_CPLUSPLUS=y
CONFIG_LIB_CPLUSPLUS=y
CONFIG_NEWLIB_LIBC=y
CONFIG_STD_CPP20=y
CONFIG_NEWLIB_LIBC_FLOAT_PRINTF=y
CONFIG_CBPRINTF_FP_SUPPORT=y
Can you tell me the right way to print uint64_t values in decimal?
Thanks.
Parents Reply
  • Hi, I was using the snippet of code as shorthand for what I was doing in principle.

    Here is how the code works.  I'm wrapping the snprintf in a convenience function to make it easier to call.  I'm converting values to strings.

    static const uint8_t BUF_SIZE = 64;
    static char BUF[BUF_SIZE];
    
    template <typename T>
    const char *StrC(const char *fmt, T val)
    {
        int bufSize = snprintf(BUF, BUF_SIZE, fmt, val);
    
        return FormatTemplateBase::BUF;
    }

    The point is that when I use the format string for uint64_t it doesn't work as described above, even when used outside of the wrapper.

    Can you help?

    Thanks.

Children
Related