Created
March 15, 2017 17:36
-
-
Save sekrasoft/14a8871b1159411c084de072b90df68d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#define TO_STRING1(X) #X | |
#define TO_STRING(X) TO_STRING1(X) | |
#define LINE TO_STRING(__LINE__) | |
#define malloc(N) log_p(malloc(log_s(N, "CALLING MALLOC @ " \ | |
LINE)), "CALLED MALLOC @ " LINE) | |
#define free(p) free(log_p(p, "FREE @ " LINE)) | |
size_t log_s(size_t N, const char * context) { | |
printf("### %s (%d)\n", context, N); | |
return N; | |
} | |
void* log_p(void* p, const char * context) { | |
printf("### %s (%p)\n", context, p); | |
return p; | |
} | |
int main(void) { | |
printf("hello!\n"); | |
char* m = malloc(10); | |
printf("allocated: %p\n", m); | |
m[0] = 'a'; | |
m[1] = 0; | |
printf("m='%s'\n", m); | |
if(m != NULL) free(m); | |
printf("freed: %p\n", m); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Результат исполнения: