help needed about dynamic space allocation
fano at lifia.UUCP
fano at lifia.UUCP
Sat Nov 22 04:12:26 AEST 1986
forgive the ignorance of a novice C-programmer:
I need advice on dynamic space allocation for multidimensionnal arrays:
Here is a way I have implemented dynamic allocation for a 2 X 2 matrix named
sig in a C-source file named combin1.c:
(I'll explain further the reason why I'm not satisfied with that solution)
BEGINNING OF THE EXAMPLE:
float **sig; /* matrix declaration */
....
sig = (int *)malloc(n * sizeof(int)); /* allocates space for sig */
for ( i = 0; i < n; i++) /* lines adresse */
{
sig[i] = (float *)malloc(n * sizeof(float));/* allocates space for */
} /* columns of line i */
....
for (i = n-1 ; i >= 0; i--)
{
free(sig[i]); /* desallocates space */
}
free(sig);
END OF THE EXAMPLE
during the compiling time, I get the following warning:
"combin1.c", line 220: warning: illegal pointer combination
any-way the program runs, and gives the desired results.
The compiler message suggests that I didn't use the proper way to implement
matrix dynamic allocation. So, could someone over there give me advices for
a cleaner solution.
Thanx.
--
fano rampa*
///////////////////////////////////////////////////////////////////////////////
"Carmen lips are more exciting than Common lisp..."
-G.Bizet-
fano at lifia.UUCP or mcvax!lifia!fano
More information about the Comp.lang.c
mailing list