Creator doesn't know qint8 is signed


  • Qt Champions 2016

    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.


  • Moderators

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


  • Qt Champions 2016

    @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.


  • Moderators

    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.


  • Qt Champions 2016

    @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.


  • Moderators

    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?


  • Qt Champions 2016

    @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).


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.