views:

176

answers:

1

I have the code:

unsigned int length = strlen(somestring);

I'm compiling with the warning level on 4, and it's telling me that "conversion from size_t to unsigned int, possible loss of data" when a size_t is a typedef for an unsigned int.

Why!?

Edit:

I just solved my own problem. I'm an XP user, and my compiler was checking for 64 bit compatibility. Since size_t is platform dependent, for 64 bit it would be an unsigned long long, where that is not the same as an unsigned int.

+6  A: 

Because unsigned int is a narrower type on your machine than size_t. Most likely size_t is 64 bits wide, while unsigned int is 32 bits wide.

EDIT: size_t is not a typedef for unsigned int.

Billy ONeal
Well, `size_t` _is_ a typedef for `unsigned` on some systems. It won't be on LP64 and LLP64 systems though. :-)
James McNellis
@James McNellis: Maybe, but the standard doesn't define it that way :)
Billy ONeal