Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Warning when using qint64 with PRIi64 on 64 bit linux
Forum Updated to NodeBB v4.3 + New Features

Warning when using qint64 with PRIi64 on 64 bit linux

Scheduled Pinned Locked Moved Unsolved General and Desktop
17 Posts 3 Posters 4.8k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • m.sueM m.sue

    Hi @DuBu

    PRIi64 should return "lli" on a 64-bit system. So maybe you use a 32-bit system or (cross-)compiler.

    -Michael.

    DuBuD Offline
    DuBuD Offline
    DuBu
    wrote on last edited by
    #4

    @m.sue Yes, I thought so too. But it doesn't! Here's a snippet from inttypes.h:

    # if __WORDSIZE == 64
    #  define __PRI64_PREFIX	"l"
    #  define __PRIPTR_PREFIX	"l"
    # else
    #  define __PRI64_PREFIX	"ll"
    #  define __PRIPTR_PREFIX
    # endif
    # define PRIi64		__PRI64_PREFIX "i"
    

    And the if branch is active (i.e __WORDSIZE == 64 is true).
    So PRIi64 returns "li" on my system. The compiler is the one I already mentioned.

    m.sueM 2 Replies Last reply
    0
    • DuBuD DuBu

      @m.sue Yes, I thought so too. But it doesn't! Here's a snippet from inttypes.h:

      # if __WORDSIZE == 64
      #  define __PRI64_PREFIX	"l"
      #  define __PRIPTR_PREFIX	"l"
      # else
      #  define __PRI64_PREFIX	"ll"
      #  define __PRIPTR_PREFIX
      # endif
      # define PRIi64		__PRI64_PREFIX "i"
      

      And the if branch is active (i.e __WORDSIZE == 64 is true).
      So PRIi64 returns "li" on my system. The compiler is the one I already mentioned.

      m.sueM Offline
      m.sueM Offline
      m.sue
      wrote on last edited by m.sue
      #5

      Hi @DuBu

      I have the same compiler and the same code as you in /usr/include/inttypes.h. But PRIi64 returns "lli". No idea what could be the difference :-/

      Ah I just tested: I get the same error as you in main.cpp but in some sub-dll where I use all my PRI* strings everything works fine. Interesting.

      -Michael.

      1 Reply Last reply
      0
      • DuBuD DuBu

        @m.sue Yes, I thought so too. But it doesn't! Here's a snippet from inttypes.h:

        # if __WORDSIZE == 64
        #  define __PRI64_PREFIX	"l"
        #  define __PRIPTR_PREFIX	"l"
        # else
        #  define __PRI64_PREFIX	"ll"
        #  define __PRIPTR_PREFIX
        # endif
        # define PRIi64		__PRI64_PREFIX "i"
        

        And the if branch is active (i.e __WORDSIZE == 64 is true).
        So PRIi64 returns "li" on my system. The compiler is the one I already mentioned.

        m.sueM Offline
        m.sueM Offline
        m.sue
        wrote on last edited by
        #6

        Hi @DuBu

        It works if you use int64_t instead of qint64.

        -Michael.

        DuBuD 1 Reply Last reply
        0
        • m.sueM m.sue

          Hi @DuBu

          It works if you use int64_t instead of qint64.

          -Michael.

          DuBuD Offline
          DuBuD Offline
          DuBu
          wrote on last edited by
          #7

          @m.sue I can't change that, it's code from Qt (i.e QElapsedTimer::elapsed()).

          m.sueM 1 Reply Last reply
          0
          • DuBuD DuBu

            @m.sue I can't change that, it's code from Qt (i.e QElapsedTimer::elapsed()).

            m.sueM Offline
            m.sueM Offline
            m.sue
            wrote on last edited by
            #8

            Hi @DuBu

            You could probably cast it to int64_t. It is ugly, though.

            -Michael.

            1 Reply Last reply
            0
            • jsulmJ jsulm

              @DuBu Use ll instead of li, see http://www.cplusplus.com/reference/cstdio/printf/

              DuBuD Offline
              DuBuD Offline
              DuBu
              wrote on last edited by
              #9

              @jsulm Yes, but I want to use the PRI macros.

              1 Reply Last reply
              0
              • DuBuD Offline
                DuBuD Offline
                DuBu
                wrote on last edited by
                #10

                I wonder what is wrong, the qint64 which is actually a long long int or the PRIi64 macro which is actually a "li"?

                m.sueM 1 Reply Last reply
                0
                • DuBuD DuBu

                  I wonder what is wrong, the qint64 which is actually a long long int or the PRIi64 macro which is actually a "li"?

                  m.sueM Offline
                  m.sueM Offline
                  m.sue
                  wrote on last edited by m.sue
                  #11

                  Hi @DuBu

                  PRIi64 together with int64_t is "lli", together with qint64 it is "li". The PRI macros probably do not know what to do about qint64. Maybe it's a compiler bug.

                  -Michael.

                  1 Reply Last reply
                  0
                  • DuBuD Offline
                    DuBuD Offline
                    DuBu
                    wrote on last edited by
                    #12

                    Ok, thanks guys! I ended up by using PRIi64 and casting qint64 to int64_t when necessary.

                    m.sueM 1 Reply Last reply
                    0
                    • DuBuD DuBu

                      Ok, thanks guys! I ended up by using PRIi64 and casting qint64 to int64_t when necessary.

                      m.sueM Offline
                      m.sueM Offline
                      m.sue
                      wrote on last edited by
                      #13

                      Hi @DuBu

                      Qt could fix it by defining typedef int64_t qint64; instead of typedef long long qint64; on Linux. But, of course, there could be some side effects of that change that I do not see. Maybe some supported compiler does not yet have the int64_t type.

                      -Michael.

                      jsulmJ 1 Reply Last reply
                      0
                      • m.sueM m.sue

                        Hi @DuBu

                        Qt could fix it by defining typedef int64_t qint64; instead of typedef long long qint64; on Linux. But, of course, there could be some side effects of that change that I do not see. Maybe some supported compiler does not yet have the int64_t type.

                        -Michael.

                        jsulmJ Offline
                        jsulmJ Offline
                        jsulm
                        Lifetime Qt Champion
                        wrote on last edited by
                        #14

                        @m.sue long long is not necessarily always 64 bit. The length of integral types in C/C++ isn't specified exactly. The only thing specified is:

                        char <= short <= int <= long int <= long long
                        

                        The exact size of each type depends on platform and compiler.

                        https://forum.qt.io/topic/113070/qt-code-of-conduct

                        m.sueM 1 Reply Last reply
                        0
                        • jsulmJ jsulm

                          @m.sue long long is not necessarily always 64 bit. The length of integral types in C/C++ isn't specified exactly. The only thing specified is:

                          char <= short <= int <= long int <= long long
                          

                          The exact size of each type depends on platform and compiler.

                          m.sueM Offline
                          m.sueM Offline
                          m.sue
                          wrote on last edited by
                          #15

                          Hi @jsulm

                          Ok, but as int64_t is guarantueed to be 64-bit, it is not guarantueed to be defined for every compiler. So it's no good choice for qint64.

                          Nevertheless Qt should find a way to use it without warnings in printf with the new PRI macros, They are just about invented to use with long longs that are or are not 64-bit depending on the compiler/machine.

                          -Michael.

                          jsulmJ 1 Reply Last reply
                          0
                          • m.sueM m.sue

                            Hi @jsulm

                            Ok, but as int64_t is guarantueed to be 64-bit, it is not guarantueed to be defined for every compiler. So it's no good choice for qint64.

                            Nevertheless Qt should find a way to use it without warnings in printf with the new PRI macros, They are just about invented to use with long longs that are or are not 64-bit depending on the compiler/machine.

                            -Michael.

                            jsulmJ Offline
                            jsulmJ Offline
                            jsulm
                            Lifetime Qt Champion
                            wrote on last edited by jsulm
                            #16

                            @m.sue Well, qint64 is guaranteed to be 64 bit, so you cannot use long long to typedef it.
                            int64_t is defined in C++11 and as Qt requires C++11 since quite some time it is perfectly valid to use int64_t in my opinion.
                            And why use printf in C++ at all?

                            https://forum.qt.io/topic/113070/qt-code-of-conduct

                            DuBuD 1 Reply Last reply
                            0
                            • jsulmJ jsulm

                              @m.sue Well, qint64 is guaranteed to be 64 bit, so you cannot use long long to typedef it.
                              int64_t is defined in C++11 and as Qt requires C++11 since quite some time it is perfectly valid to use int64_t in my opinion.
                              And why use printf in C++ at all?

                              DuBuD Offline
                              DuBuD Offline
                              DuBu
                              wrote on last edited by DuBu
                              #17

                              @jsulm Yes, to use int64_t is perfectly valid. So Qt should use it in their own classes.
                              Why use printf in C++? Cause it sits deep down in a C library we want to use in C++ as well. And also: why not?

                              1 Reply Last reply
                              0

                              • Login

                              • Login or register to search.
                              • First post
                                Last post
                              0
                              • Categories
                              • Recent
                              • Tags
                              • Popular
                              • Users
                              • Groups
                              • Search
                              • Get Qt Extensions
                              • Unsolved