Old Wolf said:
No. It is ugly. And that isn't a trival issue. When code looks like line
noise it becomes unreadable, and then it gets hard to maintain, and you get
bugs.
As happened to Perl and C++. size-t is admittedly only a small step in that
direction, but its a step in the wrong direction.
>
When was the last time you had a chunk of memory with
a negative size?
When was the last time you had a negative amount of money in your pocket?
However you can have an negative amount in your account. Intermediate
calculations of the sizes of memory objects may give negative results.
C doesn't interface with other languages.
Yes it does. C frequently has to call non-C code, or be called by it.
Anything that makes that process easier is a good thing.
You should use it for describing a size of memory. Would you
also criticise 'char' because it is a misnomer when not used to
refer to a character?
Yes I would. The fact that char and byte are the same thing in C is a major
headache to anyone who has had to use a non-English language. However that
is somethign we are stuck with. size_t is a newcomer which can still, just,
be syuppressed if we are determined enough to squeeze it out of our nice C
code.
Usually it is an alias for an existing type
It is another type swilling about. The fact that it probaly has the same
number of bits as another type is neither here nor there.
Now Bloggs writes
setpixels(size_t *x, size_t *y, size_t N)
because size_t is the right thing for an index, right?
Muggins writes
int *xvals;
int *yvals;
int N;
Because his pixel co-ordiantes are integers.
Now he calls Blogg's setpixels() routine. Oh dear. The code becomes a mass
of castings and type conversions. It's the two standards problem. We need
one standard way of representign integers in the machine.
How would you implement malloc without size_t ?
Standard:
malloc() takes an numerical type as its argument which must be an integer.
Normal application
void *malloc(int N)
{
assert(N >= 0);
}
Because on normal machines there simply isn't enough memory to overflow the
range of a singed integer, so this isn't a problem.
squeezed compiler, maybe on an embedded machine
void *malloc( unsigned long long N)
{
}
weird compiler (why not do this?)
void *malloc(double N)
{
assert(N == floor(N));
}
0.5 out of 6 for you (at best)
Don't be arrogant. Maybe you don't have the intellectual capacity to
appreciate the strength of the point being made.