Re: questions about size_t
- From: "void * clvrmnky()" <clvrmnky.invalid@xxxxxxxxxxxxxxxxxxx>
- Date: Thu, 27 Apr 2006 13:13:39 -0400
edware wrote:
Hello,size_t is an unsigned integer type large enough to hold the value returned from sizeof. The actual int types that correspond to size_t can vary.
I have some questions about the size_t type.
First, what do we know about size_t? From what I have
read I believe that it is an unsigned integer,
but not necessarily an int. Am I correct?
Does this mean that if I need to compare two variables,Since size_t is defined as being unsigned, as long as you are sure your int is not negative, the implicit casting (and I'm fuzzy on that) during the compare should be ok.
one of the size_t type, should the other also be a size_t
variable? There could be problems if I compare it with an
int, if those have different sizes, right?
Most of the time when I make for loops, I use an int variable
as index, like for (int i = 0; ...)
Should I change that to size_t if I need to compare the i
variable with the return value of strlen(), for example?
I think that just adds more things to think about,Well, since size_t will always fit whatever sizeof can return, I'm thinking that an int type holds an integer value and a size_t type definitions hold some sort of size representation. Indeed, these are closely related, but the size of an object is certainly different than the value of it.
wouldn't it be easier to just use an unsigned int, instead
of the size_t variable for strlen, sizeof, etc. ?
So, those functions that depend on sizes would be more correct in using one of the type definitions (e.g., wchar_t, size_t).
Whats the benefit of size_t?
Is there advantage using it for your own stuff, like
struct {
size_t size;
void *stuff;
};
or
make_balloon(size_t balloonsize);
or should it only be used for the standard functions?
A good question. I pretty much use integer types interchangeably, though I'm sure I'm missing something.
.
- References:
- questions about size_t
- From: edware
- questions about size_t
- Prev by Date: Re: difference between scanf("%i") and scanf("%d") ??? perhaps bug in VS2005?
- Next by Date: Re: questions about size_t
- Previous by thread: questions about size_t
- Next by thread: Re: questions about size_t
- Index(es):
Relevant Pages
|
|