M
Malcolm McLean
As long as the subset is both expressive enough to allow you to doThen you have to know the boundaries of that subset (or of an even
smaller subset of that subset) to avoid going beyond them. I don't see
how you can know the boundaries of the subset without understanding the
difference between your mental model and the one described in the
standard.
Nor do I know why any serious C programmer would be satisfied with not
understanding the language.
what you want easily, and Turing complete, there's no particular reason to go beyond it.
C would be nicer with decent 2D arrays, but you don't have them, and it's
no great hardship to go array2d[y*width+x]. So we don't need all the
complications of the 2D syntax. Even in the rare cases when we know the
dimensions at compile time, and can use a 2D array, we might as well
use the index calculation method, if we use it everywhere else in the
program.
For some reason we need a list of the number of days worked, per yearI don't understand that at all. Are you saying that a fixed-size array
isn't likely to be as long as 100 elements, and is more likely to be
allocated via malloc with a size based on the program's input?
A lookup table indexed by 8-bit characters will have 256 elements.
Input buffers are commonly 1024 or more characters. Fixed-size data for
some common algorithms can be much bigger than that.
In any case, you claim that
int array[100];
"isn't declaring an array" is quite simply false.
of an employee's service with the company.
It's hard to say what the maximum is, recently, for example, the UK
retirement age was raised from 65 to 67. But there's absolutely no
way someone could have as many as 100 year's service.
So
int getsizeofgoldwatch(int recruitmentdate, DATABASE *db)
{
int daysworked[100];
int currentdate = getcurrentdate();
int N = currentdate - recruitmentdate + 1;
int i;
for(i=0;i<N;i++)
daysworked = getdaysworked(db, recruitmentdate + i);
return fancyalgorithm(daysworked, N);
}
So the buffer is 100 ints, the array is the first N.
Now if we decide we don't want to take up all that stack space, or
if we decide that we need to support any length of service (in case
we employ Methuselah so something), we can go to a buffer on the
heap without changing much of the code.