the death of optimizing compilers
Name:
Anonymous
2015-04-18 0:15
Name:
Anonymous
2015-04-18 20:17
>>18And just what language
can't you do that in?
#include <stdio.h>
#include <stdlib.h>
struct Node{
void* data;
int size;
struct Node* next;
};
struct Node* callstack;
void push(void* data, int size){
struct Node* n = (struct Node*)malloc(sizeof(struct Node));
n->data = data; n->size = size; n->next = callstack;
callstack = n;
}
struct Node* pop(){
struct Node* n = callstack;
if(n == NULL) return n;
callstack = callstack->next;
return n;
}
void initstack(){
callstack = (struct Node*)malloc(sizeof(struct Node));
callstack->data = callstack->next = NULL; callstack->size = 0;
}
void println(){
struct Node* n = pop();
int len = (int)n->data;
for(int i = len; i > 0; i--){
n = pop();
if(n == NULL) break;
if(n->size == sizeof(int))
printf("%d", (int)n->data);
else if(n->size == sizeof(char))
printf("%s", (char*)n->data);
else continue;
free(n);
}
printf("\n");
}
int main(int argc, char** argv){
initstack();
push((void*)".", sizeof(char));
push((void*)"\b\b}", sizeof(char));
for(int i = 0; i < 50; i++){
push((void*)", ", sizeof(char));
push((void*)i, sizeof(int));
}
push((void*)"This is a set: {", sizeof(char));
push((void*)(2 + 50 * 2 + 1), sizeof(int));
println();
return 0;
}
Newer Posts