Charlie Gordon said:
You conveniently snipped all the evidence
It is appropriate to snip material unless I am directly commenting on it.
In this case, I was commenting not on the material I snipped but on your
claim that I was playing with words. If you meant "conveniently"
literally, fine, and I'm glad I was able to present my reply in a way that
you found convenient. But if you meant it ironically, it's a baseless
slur.
, so here it is:
First example:
len, longest, maxlinelen are string lengths: they measure a count of
objects
in an array, which is why they were made size_t.
len is populated like this: len = strlen(rest) + 1;
and used like this:
if(len > longest)
{
size_t prev;
longest = len;
while(prev = longest, longest &= (longest - 1))
{
continue;
}
longest = prev * 2;
}
None of them is used for indexing into an array.
Unless n is intended to
count lines for allocating an array, size_t is not the proper type for
it: either you know that there are never more than 65535 lines in the
file and unsigned int is sufficient, or you don't and long or unsigned
long should be your choice.
Agreed. Amazing what turns up in these discussions, isn't it? It should be
unsigned long (and now is).
Total: at least 50% of integers are size_t because they measure an array
or index into one.
Sure, but that's not what Malcolm is saying. He's saying that most integers
are used as indices, or are ultimately used to derive indices. What you
are trying to show is that those integers that I have deliberately chosen
to be of type size_t are used for object counts or sizes. Yes, *some* of
those size_t are used for indexing into an array, but his claim was that
most (i.e. at the very least, more than half) integral type objects are
used for indexing into arrays. My data showed that this claim was not true
in the given arbitrary sample. If you want to argue that more than half my
size_t objects were used for indexing into an array, well, I would not be
surprised if that were true, but it turns out that it isn't true in that
example.
Second example:
46 total variables.
16 variables used as index per your own admission.
Oh, please don't be so dramatic. It's not a question of admitting this and
confessing that, but a question of examining Malcolm's claim that most
integers are used as indices into arrays.
7 variables use to measure strings or parts of strings, ie counts of
objects in arrays.
Yes. Counts are not indices, however.
wcount and pos are counts of objects for which size_t is not the proper
type.
I agree about wcount (which I've now fixed to be unsigned long).
RangeStart and RangeEnd track ranges: cannot tell from context if they
qualify as offsets in an array or as counts of objects unrelated to
memory, such as lines, for which you chose the type int anyway.
They mark the lower and upper limits of a loop whose counter is used for
indexing into an array. I agree that the loop counter is used for indexing
(and I recorded it as such), but I do not agree that the limits are used
for indexing.
Of course argc also qualifies as the count of objects in the argv array.
Yes. It's a count. It ought to be size_t.
Again at least 50% of integer variables are size_t because they measure
an array or index into one.
Again, that's not Malcolm's claim. He says that most integers are used for
indexing arrays. I will agree that size_t is often used for indexing
(which is really another way of saying "counting objects"), but there are
many more uses for integers than mere indexing, important as that use
undoubtedly is.
I'm just trying to use common sense to explain what I think Malcolm means
in his assertion: type size_t is only sensible for variables that
represent
sizes, indices, and counts of objects in arrays in memory.
I agree that those are the proper uses of size_t - and they describe how I
use it myself (except when I mistakenly use it for other things, and
you've spotted a couple of those yourself). But I don't think that's what
Malcolm means at all.
"Most" is probably too much,
Right.
but to
say that integer variables are "primarily" used for such purposes as
indexing or measuring object counts in memory arrays seems right to me.
Fine, but it doesn't seem right to me. It seems to me that it would be
closer to the mark to say that indexing is one of the very many important
uses to which integers are put. If he means that integers are used more
frequently for indexing than for any other single purpose, then I might
even agree (or at least not bother to disagree), but to claim that this
frequency exceeds 50% seems to me to be an exaggeration.