Mail Archives: djgpp/1998/06/30/15:15:26
Destination: Federico Spinazzi <federico AT SysPr03 DOT disat DOT unimi DOT it>
From: Gruber Gerhard
Group: comp.os.msdos.djgpp
Date: Tue, 30 Jun 1998 17:02:41 +0200 (MET DST):
>I think
>here you are declaring pointer to a 2-dimensional array. Why not to use
I suppose you never tested that code?
>#include <conio.h>
>#include <stdlib.h>
>
>int main()
>{
>
>int **vertice, count, allocated;
>
>/*
>Maybe you know that you need a 10-element array. However:
>*/
>
>vertice = (int **)malloc(sizeof(int *);
) missing
>if (vertice == NULL)
> { cprintf("Not enough memory"); exit(0); }
>
>for (allocated = 1, count = 0; count<10; count++)
> {
> vertice[count] = (int *)malloc(HOW_MANY_I_NEED);
I suggest using malloc(HOW_MANY... * sizeof(int)) instead.
>You should be able to read and write in vertice[][].
> BUT, why MSS complain thet I have corrupted memory calling
Because if you reference the memory this way you would need one single chunk
of memory that is big enough for the array.
assuming int m[10][10]; you need to allocate a block of 100 ints assigned to
m. Your above code doesn't do this because you'd allocate 10 pointers! to
ints. But that doesn't work either because the compiler needs to know how big
the array is in order to calculate the indizes when you access the array.
>free(vertice) ?
>
>Is it a correct waring o a bug in it?
It is correct.
>I've written to MSS writers but they are too busy ...
:)))) What did you expect? :)
>I'm right or not ?.
You are right. they really are to busy. :) SCNR.
--
Bye,
Gerhard
email: sparhawk AT eunet DOT at
g DOT gruber AT sis DOT co DOT at
Spelling corrections are appreciated.
- Raw text -