use strict;
use warnings;
use Inline C => <<'END_OF_C';
void foo() {
char *s = (char *)malloc(100);
sprintf(s, "%s", "hello there");
printf("'%s'\n", s);
free(s);
}
END_OF_C
foo();
__END__
####
// gcc y.c
#define _GNU_SOURCE
#include
#include
void free(void *ptr);
void free(void *ptr){
printf("my free called\n");
}
void foo() {
char *s = (char *)malloc(100);
sprintf(s, "%s", "hello there");
printf("'%s'\n", s);
free(s);
}
void main(void){ foo(); }
####
% a.out
'hello there'
my free called
####
// gcc x.c
#define _GNU_SOURCE
#include
#include
#define free myfree
void myfree(void *ptr);
void myfree(void *ptr){
printf("my free called\n");
}
void foo() {
char *s = (char *)malloc(100);
sprintf(s, "%s", "hello there");
printf("'%s'\n", s);
free(s);
}
void main(void){ foo(); }