Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

malloc() and free()

Name: Anonymous 2011-01-18 22:44

#include <stdlib.h>

int * b;

int main(void)
{
    int * a = NULL;
    a = (int *) malloc(sizeof(int));
    b = &a;
    free(b);
    return 0;
}


Would this result in a memory leak? If yes, why?

Name: Anonymous 2011-01-22 7:39

>>44
That's a special case in C, instated due to the frequent need to pass around untyped memory addresses.

That is not the case in high-level languages, and there is no direct parallel. In particular, the object base class is normally not implicitly convertible to any class.

C++ tossed it due to delusions of high-levelness, to discourage C-style code and interfaces.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List