Re: What *is* a CtrlID?

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance




"Joseph M. Newcomer" <newcomer@xxxxxxxxxxxx> ha scritto nel messaggio news:16ban49c253ov4c0q0q6f7iqtechtdq64f@xxxxxxxxxx

Microsoft is terribly confused about negative numbers, because they started using Win16
and never really understood the qualifier 'unsigned'. How is it possible to have a signed
value for the length of a string or an array? This could only make sense if you could
have a negative length.

Joe: for the signed/unsigned thing you mentioned here, I must confess that considering my (much smaller than yours) experience, I came to the conclusion of prefering the signed integers for loops, etc.

In the past I was hit by some bugs in some code, like this:

<code>

unsigned count;
....

while (--count > 0)
{
// do something
...
}

</code>

This is an infinite loop (and it is subtle to detect, especially if you are not an experienced programmer, if this is the first time you see that bug, and if this loop is immersed in other complex "real world" code).
The key in that bug is the 'unsigned' count variable. If you use just the *signed* 'int', everything is fine.

There are also other cases similar to that shown above.

Basically, I found that just using signed integer ('int') even for data that is unsigned in his nature (like a length of a string), saves from subtle bugs.
(At least, if there is some data that is unsigned in nature, I like putting an ASSERT like ASSERT( someLength > 0 ); but store this variable in a signed 'int'.)

And if there is a need to store values bigger than 2^31-1 = 2,147,483,647 (the maximum positive value a 32-bit int can store), I would use a 64-bit signed integer.

Of course, I'm open to listen to your experiences and insights about that.

Thanks,
Giovanni


.



Relevant Pages

  • Re: argparse parser stores lists instead of strings
    ... even if I explicitly tell it to store a string. ... loop through all the options and convert each option to a string, ... Gabriel Genellina ...
    (comp.lang.python)
  • Listbox Help!
    ... what I would like to do is loop through these values and store them in a ... string will hold "2" if there are 2,5,8,12,15 I would like my string to hold ... Damon ...
    (microsoft.public.vb.general.discussion)
  • RE: reference counting and PyTuple_SetItem
    ... is truly the bottleneck, then it *may* be good to trade off maintainability ... But what you're doing in the C loop here is almost certainly ... at all -- it's buying you bugs, but I'm not sure it's buying you anything ...
    (comp.lang.python)
  • Re: Crazy Testing ideas
    ... > interesting bugs? ... Something on the lines of Shoe testing as James Bach ... Each test has some cost and and some value. ... string, then copying it ten times; then copy the new string ten times; ...
    (comp.software.testing)
  • Re: NullPointerException
    ... > language in which it's not possible to observe a null value. ... I haven't written a programming language for ages. ... String getAddress(); ... My point of view is of someone who wants to reduce bugs. ...
    (comp.lang.java.programmer)