E
edware
Hello,
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,
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,
wouldn't it be easier to just use an unsigned int, instead
of the size_t variable for strlen, sizeof, etc. ?
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?
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,
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,
wouldn't it be easier to just use an unsigned int, instead
of the size_t variable for strlen, sizeof, etc. ?
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?