Denys Vlasenko: [ Charset ISO-8859-1 converted... ] > On Tuesday 01 July 2008 09:24, Sajish V wrote: > > Thanks for the reply, Denys. > > My question was, why doesn't gcc catch it during compilation? It is clear that we are trying to free a variable from stack. Shouldn't gcc flag an error for this during compilation? > > How gcc can know that free() is not supposed to be used like that? IIRC, in certain circumstances, the compiler prints a warning when a program tries to use a local variable or parameter, allocated on the stack, outside of its scope. However, in many cases, the compiler cannot make assumptions about where the space is actually allocated. A program can't free a static variable, anyway, only the space pointed to by a variable. So the compiler itself would not consider that to be invalid. -- Ctalk Home Page: http://www.ctalklang.org