ma******@pegasus.cc.ucf.edu wrote:
| Personnaly, I use std::size_t very often in my programs, not only in
| conjuction with the standard library
Jonathan, I realize the word 'very often', nonetheless, I too try to
follow the same approach but what do you do for the case where you're
faced with vendor API's that expects unsigned.
std::size_t is unsigned. Do you mean unsigned int?
One obvious answer is
to use an unsigned. This way it rids the compiler warnings related to
potential conversions from unsigned long (size_t may be unsigned long
on said platform) to unsinged int - 'loss of data'. I'd like to belive
vendors should just use size_t in this case but ....
Use the type which suits the circumstances. Try to use a type with
which you won't need any casts. If a function expects a signed integral
and you are using an unsigned integral, it may mean that the origin is
not compatible with the destination. In most cases though, converting
an unsigned (say, an index) to a signed integral is not too much
trouble. Every case is different.
If a function expects an unsigned int and you have a std::size_t which
is a typedef for an unsigned long, just make sure you never overflow
the unsigned int. Using 3rd party libraries usually means adaptation
and tradeoffs.
Jonathan