Date: prev next · Thread: first prev next last
2011 Archives by date, by thread · List index


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

Attachment: signature.asc
Description: This is a digitally signed message part


Context


Privacy Policy | Impressum (Legal Info) | Copyright information: Unless otherwise specified, all text and images on this website are licensed under the Creative Commons Attribution-Share Alike 3.0 License. This does not include the source code of LibreOffice, which is licensed under the Mozilla Public License (MPLv2). "LibreOffice" and "The Document Foundation" are registered trademarks of their corresponding registered owners or are in actual use as trademarks in one or more countries. Their respective logos and icons are also subject to international copyright laws. Use thereof is explained in our trademark policy.