Review Request: kstyle.cpp:3187 warning: comparison between signed and unsigned integer expressions

Guy Maurel guy-kde at maurel.de
Wed Oct 14 16:48:50 BST 2009


-----------------------------------------------------------
This is an automatically generated e-mail. To reply, visit:
http://reviewboard.kde.org/r/1848/
-----------------------------------------------------------

Review request for kdelibs.


Summary
-------

The dashboard
  http://dashboard.akonadi-project.org/CDash/index.php?project=kdelibs
reports:
/.../kdelibs/kdeui/kernel/kstyle.cpp:3187 warning: comparison between signed and unsigned integer expressions

at
void  KStyle::drawComplexControl (ComplexControl cc, const QStyleOptionComplex* opt,
                                   QPainter *p,      const QWidget* w) const

The first solutionis to make a cast.
see:  kstyle-gm-9.diff

**BUT**. It isn't suffisant!
I have much more question! May be the developper has any answers.
She/he should consider this.

The warning coming from the compiler is caused bei the first part of the expression at
line 3187:
   if (lvOpt->activeSubControls == SC_All && (lvOpt->subControls & SC_Q3ListViewExpand)) {

lvOpt->activeSubControls, the left part is a "enum SubControl" defined at line 400 of file
kstyle.h defined within kdelibs/kdeui/kernel. It is an "signed integer".

SC_All is a constant, defined at the same place, but it is an "unsigned integer".
**BUT**.
This constant is defined as 0xffffffff. This are 32bit.
The same as -1 on a 32bit-computer.
NOT THE same on a 64bit-architecture.

If one want all the bits to "one", one has to change the las line of the enum to
SC_ALL= -1

A test with:
                ...
                bool a1, a2, a3;
                a1= lvOpt->activeSubControls == SC_All;
                a2= lvOpt->activeSubControls == 0xffffffff;
                a3= lvOpt->activeSubControls == -1;

The a1 and a2 produce a warning, the a3 is OK.

**What** does the developper want to do?


Diffs
-----

  /trunk/KDE/kdelibs/kdeui/kernel/kstyle.cpp 1033934 

Diff: http://reviewboard.kde.org/r/1848/diff


Testing
-------


Thanks,

Guy





More information about the kde-core-devel mailing list