Re: Type of argc
- From: Jack Klein <jackklein@xxxxxxxxxxx>
- Date: Mon, 10 Sep 2007 00:12:32 -0500
On Mon, 10 Sep 2007 03:24:05 +0000, Richard Heathfield
<rjh@xxxxxxxxxxxxxxx> wrote in comp.std.c:
Jack Klein said:
On Sun, 09 Sep 2007 07:10:35 +0000, Richard Heathfield
<rjh@xxxxxxxxxxxxxxx> wrote in comp.std.c:
<snip>
The whole point of size_t is to record object counts
and sizes, and the role of argc is to provide a count of the number
of pointers in the array to whose first element argv points, so
size_t is absolutely the right type for it.
[snip]
Chapter and verse please. [...]
I see nothing in the standard even suggesting that size_t is a good
choice for counts.
calloc, fread, and fwrite spring to mind.
And you snipped the part of my post where I mentioned that:
"And it is accepted as a
parameter by several library functions where it represents the a
memory size in bytes, and in a few cases as an additional parameter
along with a size in bytes, which will be multiplied with the size in
bytes, to yield a total size in bytes."
Nowhere in the standard that I can think of off-hand is the type
size_t used other than directly representing a size in bytes, or as a
value passed along with another size_t that does represent a size in
bytes.
In those cases where size_t is used to pass a count to a standard
library function, I believe it is _always_ used to multiply with
another size_t argument that is a size in bytes, to produce a product
that is a size in bytes.
So again, can you cite any of the following:
-- a library function that takes a single size_t parameter that does
not represent a size in bytes, or a function taking two size_t
parameters where neither of them is a size in bytes or the two size_t
values are not multiplied together to produce a total size in bytes?
-- any other place in the standard where size_t is used to represent
anything else other than a size in bytes?
-- any place where the standard recommends use of size_t for counting
anything other than a size in bytes?
While size_t can certainly be used for counts, I don't see how it
provides any benefits over any other integer type, signed or unsigned,
of sufficient range for the values it will contain.
In particular, it has no real relationship to the use of argc, because
the user program rarely cares at all about the size of the block of
memory, in bytes, taken up by the argv pointer array. Only the total
number of them.
In other words, a count of objects. My point exactly.
If argc was the size of the argv array, in bytes, the type size_t
would be appropriate. You could then obtain the argument count by
dividing argc by sizeof *argv.
The standard mandates and includes the type size_t for one specific
purpose, namely that of holding values of sizes in bytes.
Using size_t for values representing anything other than sizes in
bytes is amateurish at best, confusing at worst. And, of course,
possibly error-prone, as code may fail when ported to a platform with
a smaller size_t that the original.
Or would you replace appropriate sized signed integer types with
ptrdiff_t?
--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://c-faq.com/
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.club.cc.cmu.edu/~ajo/docs/FAQ-acllc.html
.
- Follow-Ups:
- Re: Type of argc
- From: Richard Tobin
- Re: Type of argc
- From: André Gillibert
- Re: Type of argc
- From: Richard Heathfield
- Re: Type of argc
- References:
- Type of argc
- From: ad288
- Re: Type of argc
- From: Douglas A. Gwyn
- Re: Type of argc
- From: Richard Heathfield
- Re: Type of argc
- From: Jack Klein
- Re: Type of argc
- From: Richard Heathfield
- Type of argc
- Prev by Date: Re: Type of argc
- Next by Date: Re: Type of argc
- Previous by thread: Re: Type of argc
- Next by thread: Re: Type of argc
- Index(es):
Relevant Pages
|