Re: new/delete
c language wrote:
Hi,
I am using pointer in my program. I write them like:
*DIST=new int [M+1];
and when I want to make the memory free, I write:
delete DIST;
before the "return 0".
I don't know if the way that I am doing is correct or not because I
have some segmentation fault (core dumped) error.
Any suggestions?
Thanks,
Mohsen
new/delete live in C++ world. In C the correct way is
/* some code */
int *DIST = malloc((M+1)*sizeof *DIST);
if (DIST==NULL)
{
/* error allocating memory, do whatever you wish */
}
/* some code */
free(DIST);
If you still want new/delete, please ask in compl.lang.c++ instead.
--
one's freedom stops where others' begin
Giannis Papadopoulos
Computer and Communications Engineering dept. (CCED)
University of Thessaly
http://dop.freegr.net/
.
Relevant Pages
- Re: new/delete
... c language wrote: ... I am using pointer in my program. ... and when I want to make the memory free, ... have some segmentation fault error. ... (comp.lang.c) - Re: Question on LSP
... We are talking about sibling subtypes in an existing tree. ... But that is not known until the Object Reference type is instantiated; yet the semantics of Object Reference must exist in the language meta-model prior to instantiation. ... A pointer points only to an object and messages are sent to objects. ... (comp.object) - Pointers and Teaching C++ [was Re: A little disappointed]
... like Java where *many* facilities such as raw pointer access / manipulation ... are removed in order to create a 'safer' language and stop programmers ... then it is probably wiser to teach programming using ... pointer access / manipulation is not a 'high level language'. ... (alt.comp.lang.learn.c-cpp) - Re: The Decline of C/C++, the rise of X
... > tend to be most useful for encoding Boolean values in data structures ... to freea pointer obtained from the gc, ... >> to be a useful attribute of a language. ... Template arguments are evaluated in the scope of the point of instantiation, ... (comp.programming) - Re: Obstacles for Tcl/Tk commercial application development ?
... And once I put an integer into a variable in Tcl, it stays an integer until I assign something else to that variable. ... Usually, when I code, I know the language well enough to know what types the expressions return, so I don't wind up with the wrong types in variables. ... It takes a char* as the second argument, not a pointer to the structure you're trying to write out. ... If I expect my code to pass me an open file handle, and I pass that argument to and it throws, I'm going to catch that error at the top level, log the stack trace back, clean up, and restart the processing. ... (comp.lang.tcl) |
|