Skip to content

Instantly share code, notes, and snippets.

@SharpCoder
Last active January 25, 2017 16:07
Show Gist options
  • Select an option

  • Save SharpCoder/707ec4db59688a12a1ed4b96cd9b0480 to your computer and use it in GitHub Desktop.

Select an option

Save SharpCoder/707ec4db59688a12a1ed4b96cd9b0480 to your computer and use it in GitHub Desktop.
#include <stdio.h>
int heap[1024];
unsigned long loc = 0;
void* malloc(unsigned long size) {
unsigned long oldLoc = loc;
loc += size;
void* ptr = &heap;
return ptr + oldLoc;
}
int main(int argc, char* argv[]) {
int* addr = malloc(sizeof(int) * 2);
int* addr2 = malloc(sizeof(int) * 6);
printf("Hello, world!\n");
*(addr+0) = 10;
*(addr+1) = 20;
*(addr2+0) = 15;
*(addr2+1) = 25;
*(addr2+2) = 35;
*(addr2+3) = 45;
printf("\n\nloc: %lu\n\n", loc);
printf("%d\n", *(heap+0));
printf("%d\n", *(heap+1));
printf("%d\n", *(heap+2));
printf("%d\n", *(heap+3));
printf("%d\n", *(heap+4));
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment