Re: Unexpected compiler behavior relating to size_t and boost -
Visual Studio 2005.
On Jul 14, 7:42 pm, Juha Nieminen <nos...@thanks.invalid> wrote:
Unknownmat wrote:
What's interesting to me is that I am very careful about
using size_t - I never need to typecast between unsigned and size_t
(unless I'm forced to by a library API or something). In the example
I posted above, in fact, I'm not even USING the vector< size_t> object
- there's simply no way this object could cause a conversion error.
That's the funny side-effect of that bug: Even if there isn't
even a single "int" or "unsigned int" in the entire program,
only size_t (and some template, which is what usually causes
the problem), the compiler will still trigger a warning about
an inexistent "unsigned int".
(The problem is understandable because when compiling a 32-bit
program size_t *is* an unsigned int, but other compilers are
able to retain the info that it was, actually, a size_t all
the way and they don't give any warnings.)
I think you have it backwards. Other compilers simply consider
it an unsigned int (or whatever), and get on with it; they don't
try to treat size_t differently from whatever it is typedef'ed
to.
Which is, of course, what the standard says the compiler should
do.
Of course, there's nothing wrong with keeping the fact that this
unsigned int was originally a size_t, for things like error
messages, e.g. displaying std::vector< size_t ... > instead of
std::vector< unsigned int ... >. But in practice, most don't
seem to: if I write:
std::vector< std::size_t > v ;
v.push_back( 1, 2 ) ;
both g++ and Sun CC complain about an error using a member
function of "std::vector<unsigned int, std::allocator<unsigned
int> >" (g++) or "std::vector<unsigned>" (Sun CC). Only VC++
retains this information, displaying an error in
"std::vector<_Ty>", but later indicating that _Ty=size_t (which
is actually pretty nice---it's nice, too, that both Sun CC and
VC++ omit mentionning the allocator).
--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orient=E9e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S=E9mard, 78210 St.-Cyr-l'=C9cole, France, +33 (0)1 30 23 00 34