Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Solved Creator doesn't know qint8 is signed

    Tools
    qtcreator
    3
    7
    1289
    Loading More Posts
    • 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.
    • kshegunov
      kshegunov Moderators last edited by kshegunov

      I had to debug some code of mine when I stumbled on this (last line is the offending one):
      Debug window

      Does anyone have an idea whether there's some configuration that I had missed (I don't remember having a problem with this before) or perhaps there's some regression in the debug helper? Ideas, suggestions?

      Qt Creator version is 3.6.1

      Kind regards.

      EDIT:
      Okay, I posted a bug report for this. As it seems @mrjj was able to reproduce it on windows with mingw.

      Read and abide by the Qt Code of Conduct

      K 1 Reply Last reply Reply Quote 0
      • K
        koahnig @kshegunov last edited by

        @kshegunov
        Is this limited to windows and MinGW respectively to a specific tool chain?

        Vote the answer(s) that helped you to solve your issue(s)

        kshegunov 1 Reply Last reply Reply Quote 0
        • kshegunov
          kshegunov Moderators @koahnig last edited by kshegunov

          @koahnig
          I have encountered in on Linux x64 (Debian testing 4.5.0 kernel) with Qt Creator 3.6.1 and gdb. @mrjj reproduced on Windows 10 with mingw and creator 3.6.

          PS.
          Curiously enough, char works fine. Only qint8 (which is typedefed as a signed char) is problematic.

          Read and abide by the Qt Code of Conduct

          1 Reply Last reply Reply Quote 1
          • Chris Kawa
            Chris Kawa Moderators last edited by Chris Kawa

            Be careful with char. It is implementation defined if it is a signed or unsigned value. Standard treats char, signed char and unsigned char as three separate types.
            In case of gcc/mingw it seems to be unsigned, therefore it works, but with MSVC toolchain char and signed char are synonymous.

            Here's an example:

            unsigned char bar  = -1; //unsigned overflows are well defined so not an error
            char          bazz = -1;
            signed char   foo  = -1;
            

            Here's how GDB with MinGW sees it:
            MinGW
            And here's a view from CDB with VS2015:
            MSVC

            So yeah there seems to be something wrong with GDB or how the value is presented in Qt Creator for signed char.

            kshegunov 1 Reply Last reply Reply Quote 0
            • kshegunov
              kshegunov Moderators @Chris Kawa last edited by

              @Chris-Kawa
              Krzyś, I hope you'd forgive the familiarity,
              I am trying to be careful. This is why I used qint8, which is properly typedefed and should be working the same on all platforms, but I do appreciate the warning! To be honest, I always thought that char should be signed (never actually checked the standard on that though), so your point is valid.

              Kind regards.

              Read and abide by the Qt Code of Conduct

              1 Reply Last reply Reply Quote 0
              • K
                koahnig last edited by

                I was running into problems with char for exactly the reason @Chris Kawa is bringing up.

                However, I consider it strange that the debugger does not distinguish as Chris is lining out. Or is it the conversion required by Qt creator, because the debugger communicates only in hex?

                Vote the answer(s) that helped you to solve your issue(s)

                kshegunov 1 Reply Last reply Reply Quote 0
                • kshegunov
                  kshegunov Moderators @koahnig last edited by

                  @koahnig

                  However, I consider it strange that the debugger does not distinguish as Chris is lining out.

                  Well, gdb shows char as signed with a correct value of -1 (I do not know where the differences from MinGW come from). So it treats char as signed, but whether char is indeed signed ... not so easy to ascertain. I could only think of doing a comparison and seeing if the compiler complains:

                  char x = -1;
                  unsigned char y = 3;
                  if (y < x);  //< If the compiler complains about signed unsigned comparison, we have our answer
                  

                  Judging from the patch it seems that it's Cretator's problem. (it also appears that the dev uploading the patch thinks all platform Qt runs on uses signed char as char).

                  Read and abide by the Qt Code of Conduct

                  1 Reply Last reply Reply Quote 0
                  • First post
                    Last post