Mail Archives: djgpp/2000/05/18/06:11:18
> > > Eli Zaretskii wrote:
> > > > You need it for portability.
> > > >
> > > > size_t is not equal to int. Its precise definition depends on
> > > > the implementation.
...
> > > > You seem to be missing the point that you shouldn't rely on
> > > > size_t and int being the same size (also: size_t is unsigned,
> > > > ssize_t is signed).
"Alexei A. Frounze" <alex DOT fru AT mtu-net DOT ru> wrote in message
news:39236A55 DOT 78749ABD AT mtu-net DOT ru...
> I've never said I _rely_. I don't use size_t in my sources. Only
> standard types: char, short, int, long int, long long,... ;)
i am sorry but this statement makes no sense. size_t is no less standard
than int, but afaik long long is not in the standard at all.
eli's warning is extremely appropriate: size_t has a well defined meaning
that "it is the safest type that can represent the size of the largest data
object you can create" (P.J. Plauger's "The Standard C Library", p.219.)
for example, the following code is not safe
int main(int argc, char *argv[]) {
unsigned len = strlen(argv[0]);
}
because unsigned int is not guaranteed to be able to hold a size_t even
though it may seem to work for now.
--
mailto:Sinan_Unur AT mail DOT com
http://unur.com/
- Raw text -