Results 1 to 4 of 4

Thread: ‘PRIu64’ print macro for uint64_t

  1. #1
    Join Date
    Aug 2012
    Beans
    185

    ‘PRIu64’ print macro for uint64_t

    Hi,
    I prefer printf() despite using C++ and I found here there's a standard way to print a uint64_t (gcc apparently uses %llu or so) called "PRIu64" but apparently it's not supported under Linux, this doesn't work for me in 12.10 amd64 with g++.
    What should I do?

  2. #2
    Join Date
    Nov 2005
    Location
    Sendai, Japan
    Beans
    11,296
    Distro
    Kubuntu

    Re: ‘PRIu64’ print macro for uint64_t

    What you should do is not use them. They are C, not C++.

    EDIT: Actually they seem to be in C++11

    Code:
    firas@itsuki ~ % cat test.cpp                   
    #include <cinttypes>
    #include <cstdio>
    
    int main(void)
    {
        uint64_t x = 5;
        printf("%" PRIu64 "\n", x);
    }
    firas@itsuki ~ % g++ -std=c++11 -o test test.cpp
    firas@itsuki ~ % ./test 
    5
    Last edited by Bachstelze; January 6th, 2013 at 11:53 AM.
    「明後日の夕方には帰ってるからね。」


  3. #3
    Join Date
    Aug 2012
    Beans
    185

    Re: ‘PRIu64’ print macro for uint64_t

    Thanks,
    C seems to work out of the box (without -std=c11):

    gcc test.c -o test
    Code:
    #include <inttypes.h>
    #include <stdio.h>
    
    int main() {
        uint64_t x = 5;
        printf("%" PRIu64 "\n", x);
        
        return 0;
    }
    ~$ ./test
    5
    ~$

    I guess I'll stick with llu or lu until recent Linux distros switch to C++11 by default.
    Last edited by bird1500; January 6th, 2013 at 01:39 AM.

  4. #4
    Join Date
    Nov 2005
    Location
    Sendai, Japan
    Beans
    11,296
    Distro
    Kubuntu

    Re: ‘PRIu64’ print macro for uint64_t

    Quote Originally Posted by bird1500 View Post
    I guess I'll stick with llu or lu until recent Linux distros switch to C++11 by default.
    You're probably going to have to wait a long time, since gcc still doesn't use C99 by default. It's totally okay to use C++11 if it is available, you just need to pass a special flag during compilation, that's what Makefiles are for.
    「明後日の夕方には帰ってるからね。」


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •