In article <eb**********@n ews.tiscali.fr>
Bernard Xhumga <xh****@tiscali .frwrote:
>Now [this code] is perfect ?
It seems nothing is ever *perfect* but at least it is all correct :-)
[snippage]
>double **A = malloc(r * sizeof( *A) );
if(!A)exit(1);
In a more-general-purpose routine, it would be fairly rude to exit
(with no error message, at that) here -- instead, the function
should return some sort of error indication to its caller, saying
"I was unable to allocate the memory you requested". For quite a
few purposes, simply exiting (preferably with a message first) is
sufficient, though.
A[0] = malloc(r * c * sizeof(**A) );
if(!A[0])exit(1);
This part is good enough, with the same caveat.
for(i=1; i<r; i++)
{
A[i] = A[0]+i*c;
if(!A[i])exit(1);
This test ("if(!A[i])") is unnecessary, though harmless. If A[0]
is not NULL, A[0] + i * c should never be NULL either.
>return(A);
}
[snippage]
>void f_mR(
double **A
)
{
free((void *)A[0]);
free((void *)A);
}
The two casts are unnecessary but harmless (since <stdlib.hwas
included in code I snipped above).
--
In-Real-Life: Chris Torek, Wind River Systems
Salt Lake City, UT, USA (40°39.22'N, 111°50.29'W) +1 801 277 2603
email: forget about it
http://web.torek.net/torek/index.html
Reading email is like searching for food in the garbage, thanks to spammers.