Files
Ciro Santilli 六四事件 法轮功 26b890f42f Factor common userland and baremetal C functions
This allows add.c to run unmodified on both!

For that to work, use int main on baremetal, and pass the return value to
the final exit.
2018-11-15 20:07:47 +00:00

22 lines
494 B
C

#include <stdio.h>
#include <stdlib.h>
int main(void) {
char c;
char *ptr = NULL;
size_t alloc_size = 1;
while (1) {
printf("enter a character\n");
c = getchar();
printf("got: %c\n", c);
ptr = realloc(ptr, alloc_size);
if (ptr == NULL) {
puts("out of memory");
break;
} else {
printf("new alloc of %d bytes at address 0x%p\n", alloc_size, ptr);
alloc_size <<= 1;
}
}
}