Created
January 6, 2019 22:39
-
-
Save markd2/097ab91de4f7b28c339834eb26d7b81e to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#import <stdio.h> | |
#import <stdlib.h> | |
// clang -g -Wall -o malloc malloc.c | |
int main(void) { | |
int *blah = malloc(sizeof(int)); | |
printf("blah on alloc: %x\n", *blah); | |
*blah = 23; | |
printf("blah after assignment: %x\n", *blah); | |
free(blah); | |
blah = malloc(sizeof(int)); | |
printf("blah after free and malloc: %x\n", *blah); | |
return 0; | |
} | |
/* | |
% uname -a | |
Darwin blah.local 17.7.0 Darwin Kernel Version 17.7.0: Thu Jun 21 22:53:14 PDT 2018; root:xn\ | |
u-4570.71.2~1/RELEASE_X86_64 x86_64 | |
% clang --version | |
Apple LLVM version 10.0.0 (clang-1000.11.45.5) | |
Target: x86_64-apple-darwin17.7.0 | |
Thread model: posix | |
InstalledDir: /Applications/Xcode-10-1.app/Contents/Developer/Toolchains/XcodeDefault.xctool\ | |
chain/usr/bin | |
% clang -g -Wall -o malloc malloc.c | |
% ./malloc | |
blah on alloc: 0 | |
blah after assignment: 17 | |
blah after free and malloc: 17 | |
*/ | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment