[Libreoffice] [REVIEW] fix for a chart crasher

Nigel Hawkins n.hawkins at gmx.com
Thu Mar 3 13:59:49 PST 2011


On Thu, 2011-03-03 at 10:32 -0500, Kohei Yoshida wrote:
> One thing to note when reading LibO's code (and also OOo's) is that, a
> lot of code that are written by the Oracle folks avoid using unsigned
> integers in favor of signed ones even though unsigned ones would make
> more sense logically.  This is the case especially in newer code, such
> as chart2 and oox.
> 
> I have no explanation for this other than to say that this practice was
> probably largely inspired by Java, which doesn't have unsigned integer
> types.

Well, there is the following quote from Stroustrup:

"The unsigned integer types are ideal for uses that treat storage as a
bit array. Using an unsigned instead of an int to gain one more bit to
represent positive integers is almost never a good idea. Attempts to
ensure that some values are positive by declaring variables unsigned
will typically be defeated by the implicit conversion rules."

The implicit conversions are implementation dependent when the value is
outside the allowed range for the type you're converting to. For some
compilers that means a bitwise conversion. I've read C++ books that
recommend avoiding unsigned for precisely that reason.

That said, I would favour using unsigned's because it makes your intent
clearer. But you do need to be very careful about mixing types.

Nigel
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 490 bytes
Desc: This is a digitally signed message part
URL: <http://lists.freedesktop.org/archives/libreoffice/attachments/20110303/da55fda5/attachment.pgp>


More information about the LibreOffice mailing list