Mail Archives: djgpp/2000/02/08/07:32:41
Eli Zaretskii <eliz AT is DOT elta DOT co DOT il> wrote:
> On Mon, 7 Feb 2000, Martin Chan wrote:
>> transposed_matrix->array=(double**)calloc(row, sizeof(double*);
>> --(transposed_matrix->array); /*offset pointer*/
[...]
> Also note that arrays in C begin from offset zero, so you should either
> begin from zero and end at row-1, or use array[i-1] in the loop body.
Not really, due to that old, bad trick of offsetting the pointer. It's
a well-known, but still fundamentally bad idea. It seems to have been
invented by the authors of the otherwise nice book 'Numerical
Recipes', for their C edition. That's what you get from
Fortran-thinking guys having been forced to write C code --- they were
so used to 1-based array indexing that nothing in the world could have
convinced them to switch to the natural 0-based one, for the C version
of their code. Instead, they move all array start pointers backwards,
by one element, and go on indexing 1-based.
The idea is bad because by definition of the C standard, the program
may segfault at this point. After the subtraction, the pointer value
may have become illegal, and the machine is allowed to trap that and
abort the program.
--
Hans-Bernhard Broeker (broeker AT physik DOT rwth-aachen DOT de)
Even if all the snow were burnt, ashes would remain.
- Raw text -