Re: Malcolm's new book
- From: "Malcolm McLean" <regniztar@xxxxxxxxxxxxxx>
- Date: Fri, 3 Aug 2007 07:18:13 +0100
"Kelsey Bjarnason" <kbjarnason@xxxxxxxxx> wrote in message news:aa3ao4-ej5.ln1@xxxxxxxxxxxxxxxxxxxxxxx
[snips]size_t didn't use to be part of the language. It's a relatively new invention designed to solve the problem of memory buffers bigger than the range of an int. Of course such buffers should seldom arise, if you obey the convention that int is the "natural" integer size of the machine.
Why would size_t be obsolete, since it does a job int does not do?
So? It exists now, it has reasons for existing now, and you are ignoring
them and as a result producing bad, broken, amateurish code.
If we allow that any array can overflow the size of an int we get the folowing
void payroll(struct Employee *emplloyees, size_t N)
{
size_t i;
for(i=0;i<N;i++)
/* so something */
}
Now N is arguably a size, though it is a slightly confusing term. However the type of i is downright misleading. It does not hold a size at all. In fact this won't be acceptable, and something will be done. Either size_t will have to be deprecated / quietly dropped, or C itself will be regarded as an "advanced" language unsuitable for beginners, and gradually be squeezed out.
I'm hoping for 1.
size_t is a kludge, and code is clearer without it. It has no place in my book, except in the introduction where I explain the conventions used, and why the code is written as it is - to show algorithm, not to be robust to extreme inputs as you would get in production code. Hence the memory allocation codes take int because the algorithms operate on integers.
If you disagree with this choice, I include an example of "real" code, an atan2 routine form Sun, so that the reader has some exposure to what production code can look like.
--
Free games and programming goodies.
http://www.personal.leeds.ac.uk/~bgy1mm
.
- Follow-Ups:
- Re: Malcolm's new book
- From: Kelsey Bjarnason
- Re: Malcolm's new book
- From: mstorkamp
- Re: Malcolm's new book
- From: Keith Thompson
- Re: Malcolm's new book
- From: Flash Gordon
- Re: Malcolm's new book
- References:
- Re: Malcolm's new book
- From: Kelsey Bjarnason
- Re: Malcolm's new book
- From: Malcolm McLean
- Re: Malcolm's new book
- From: Kelsey Bjarnason
- Re: Malcolm's new book
- Prev by Date: Re: Exercise 5-9 K&R
- Next by Date: Re: function-sections and data-sections option in gcc
- Previous by thread: Re: Malcolm's new book
- Next by thread: Re: Malcolm's new book
- Index(es):
Relevant Pages
|