Mail Archives: djgpp/2001/04/22/13:00:12
Josh wrote:
>
> ive been having some problems with freeing up some allocated memory.
> i use :
> typedef struct {
> int x,y;
> }Point;
> and
> Point *p = calloc(n, sizeof(Point));
> to create an array of N point's
> then i play with the values a bit in the array (nothing unusual)
> but when i call cfree(p);
> it will either drop back to windows (saying there was a some fault) or
> reboot my computer (this happens most of the time) :(
> after 20 odd reboots, 4 cups of coffee and alot of tinkering that got
> me nowhere, I thought i'd consult with the masters :)
>
> ive placed my C code on my homepage for people to have a look at since
> it is too long to post here. It should compile straight away without
> any errors (youll need allegro) and only the calloc() and cfree() in
> main() needs to be examined. The rest of the functions work fine and
> do their jobs (so you shouldnt have to read/understand all the little
> functions.. just a few lines in main)
>
> here it is :
> http://members.dingoblue.net.au/~10archway/djgpp/npolyswivel.c
The problem is right here:
> int main()
> {
> int i,color,n;
> // an array of N Points, used to create N-sided polygon
> //Point *p = (Point *)malloc((n) * sizeof(Point));
> Point *p = calloc(n, sizeof(Point));
> Point centroid;
>
> allegro_init();
The variable 'n' is passed to calloc before you initialize it.
Dennis Yelle
--
I am a computer programmer and I am looking for a job.
There is a link to my resume here:
http://table.jps.net/~vert/
- Raw text -