G
Gibby Koldenhof
Hiya,
Is the following portable, meaning the line:
bar -> my_free(bar);
or is this asking for trouble? (i.e. freeing the thing that is
pointing to the free call).
Cheers,
Gibby
---- test.c, compile with gcc -ansi -pedantic -Wall test.c -o test
#include <stdio.h>
#include <stdlib.h>
typedef struct {
void * (*my_malloc)(size_t);
void (*my_free)(void *);
} foo;
int main(void)
{
foo * bar = malloc(sizeof * bar);
bar->my_malloc=malloc;
bar->my_free=free;
bar -> my_free(bar->my_malloc(10));
bar -> my_free(bar);
return 0;
}
Is the following portable, meaning the line:
bar -> my_free(bar);
or is this asking for trouble? (i.e. freeing the thing that is
pointing to the free call).
Cheers,
Gibby
---- test.c, compile with gcc -ansi -pedantic -Wall test.c -o test
#include <stdio.h>
#include <stdlib.h>
typedef struct {
void * (*my_malloc)(size_t);
void (*my_free)(void *);
} foo;
int main(void)
{
foo * bar = malloc(sizeof * bar);
bar->my_malloc=malloc;
bar->my_free=free;
bar -> my_free(bar->my_malloc(10));
bar -> my_free(bar);
return 0;
}