Boost logo

Boost :

From: Paul A. Bristow (boost_at_[hidden])
Date: 2003-10-31 06:54:58


Many bugs I have written :-( ... but which the compiler has spotted before they
bit me.

I agree that you have to make a special effort to switch the compiler warnings
on
(for MSVC enabling level 4 - and it can be made the 'default' for new projects
with some twiddling).

And you have to be fastidious about getting rid of the warnings by making all
conversions explicit. (I note that there is a lot of Boost code which doesn't
meet this standard. Sometimes it is a matter of a static_cast<> but other
times, using int when unsigned would be better, often because the thing being
copied or compared with, like a std::string length, is size_type and unsigned).

And you are right that the compiler doesn't warning you about

for ( unsigned i = 5; i >= 0; i-- ) ...

which may not end happily!

Generally you have to remember to use != in tests, but since std::iterators
comparisons must use this, it's surely not a big issue.

I have never used unsigned to get more range - although it does, and is used by
standard library items, drawing on, for example:

typedef basic_string <char>::size_type size_type;

or

using basic_string <char>::size_type;

Isn't this what we should use more often?

Paul

Paul A Bristow, Prizet Farmhouse, Kendal, Cumbria, LA8 8AB UK
+44 1539 561830 Mobile +44 7714 33 02 04
mailto:pbristow_at_[hidden]

| -----Original Message-----
| From: boost-bounces_at_[hidden]
| [mailto:boost-bounces_at_[hidden]]On Behalf Of Thorsten Ottosen
| Sent: Thursday, October 30, 2003 11:02 AM
| To: boost_at_[hidden]
| Subject: [boost] Re: Re: int vs. unsigned int
|
|
| > (And in general, my experience -I never ignore signed/unsigned mismatch
| > warnings -
|
| some people might do. And they might not get warnings; nothing in the
| standard says so.
|
| > suggests that using unsigned for the never negative is the Right
| > Thing To Do. But it is tiresome at first.)
|
| what suggests it? Please be a bit clearer.
|
| -Thorsten
|


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk