Re: Proper way to input a dynamically-allocated string
- From: "Malcolm" <regniztar@xxxxxxxxxxxxxx>
- Date: Sun, 11 Dec 2005 18:36:10 +0000 (UTC)
"Joe Wright" <jwright@xxxxxxxxxxx> wrote
> #define SSIZE_MAX 2147483647
> #define INT_MAX 2147483647
> #define LONG_MAX 2147483647L
>
> ..and so see no compelling reason to type anything size_t rather than int.
>
> It is interesting to have functions prototyped with size_t parameters to
> indicate positive values. Otherwise, int works perfectly well for me.
>
Take this function
/*
trivial function that counts number of occurrences of ch in str
*/
mystrcount(const char *str, int ch)
Now basically this function is alwaysgoing to return small integers.
However, technically, someone could pass it a massive string, all set to one
character. Then an int would overflow, if size_t were bigger than an int.
Thus the function must return a size_t.
That means that the higher-level logic which calls it must also be written
with size_t, and the ugliness propagates
.
- Follow-Ups:
- Re: Proper way to input a dynamically-allocated string
- From: Keith Thompson
- Re: Proper way to input a dynamically-allocated string
- From: Joe Wright
- Re: Proper way to input a dynamically-allocated string
- References:
- Proper way to input a dynamically-allocated string
- From: Michel Rouzic
- Re: Proper way to input a dynamically-allocated string
- From: Eric Sosman
- Re: Proper way to input a dynamically-allocated string
- From: Michel Rouzic
- Re: Proper way to input a dynamically-allocated string
- From: Eric Sosman
- Re: Proper way to input a dynamically-allocated string
- From: Michel Rouzic
- Re: Proper way to input a dynamically-allocated string
- From: Flash Gordon
- Re: Proper way to input a dynamically-allocated string
- From: Michel Rouzic
- Re: Proper way to input a dynamically-allocated string
- From: Malcolm
- Re: Proper way to input a dynamically-allocated string
- From: Ben Pfaff
- Re: Proper way to input a dynamically-allocated string
- From: Joe Wright
- Proper way to input a dynamically-allocated string
- Prev by Date: Re: Speed of finding a size of an array.
- Next by Date: [OT] Re: Problem with "system" and the linux "su" command
- Previous by thread: Re: Proper way to input a dynamically-allocated string
- Next by thread: Re: Proper way to input a dynamically-allocated string
- Index(es):
Relevant Pages
|