|
From: Ioannis V. <no...@ya...> - 2001-09-16 01:53:19
|
void free(void *p) is defined in <stdlib.h> nd it ccan be used like
this.
=20
/* C program (.c) */
=20
#include <stdlib.h>
=20
int main()
{
int *p;
p=3Dmalloc(10*sizeof(int)); /* It creates an array of 10 integers on the
free store. */
p[0]=3D5;
p[3]=3D7;
/* ... */
=20
free(p); /* It deallocates the memory allocated for 10 integers */
=20
/* Now p points to nowhere, the array doesn't exist */
return 0;
}
=20
For C++ file (.cpp) you must use casting in malloc(), that is:
=20
p=3D(int *)malloc(10*sizeof(int));
=20
=20
but C++ provides more flexible mechanisms, new, new[], delete, and
delete[] so it becomes:
=20
p=3Dnew int[10];
p[0]=3D5;
p[3]=3D7;
// ...
delete[] p; =20
=20
=20
Ioannis
=20
* Ioannis Vranos
* Programming pages: http://www.noicys.f2s.com
<http://www.noicys.f2s.com/>=20
* Alternative URL: http://run.to/noicys
=20
=20
=20
-----Original Message-----
From: dev...@li...
[mailto:dev...@li...] On Behalf Of Joseph,
Brandi, & Elise VanPelt
Sent: Sunday, September 16, 2001 12:39 AM
To: dev...@li...
Subject: [Dev-C++] Hello
Hello all,
This is my first post to this list. My name is Joseph, you can call
me Blumojo (or "blu" or "mojo" for short). I really like Dev-cpp and am
thinking of sending a donation if I can get the following to work. I am
working on NeHe's OpenGL tutorials (http://nehe.gamedev.net/) which are
really good - even for a novice like me, but the code he gave was for
Visual CPP. I have worked through a couple of the problems, but have
become "stumped" on lesson 7 where the compiler has given me:
"implicit declaration of function int free()"
In his explanation, this function is used to free memory used to store
texture data.
=20
First of all, has anyone worked through these tutorials and ported
them to Dev-CPP/MinGW? If so, I would greatly appreciate the code to
help me along. Second, is there another (perhaps better) way to free
this memory?
=20
Thank you all so much for the help!
=20
-Bumojo
|