Ok, I did a silly thing: I was using g++ instead of gcc which matters when using casting with a "void *" - c++ requires more logic to do this than c does. Here is the code now:
procsim.c
/* Copy the trace file into a linked list */
int total_instructions = 0;
proc_instruction *p_inst = (proc_instruction *)emalloc(sizeof(*p_inst));
queue *trace_queue = init_queue();
proc_instruction *inst;
while (total_instructions < 5000 && fscanf(proc_tf, "%x %d %d %d %d\n",
&p_inst->address,
&p_inst->type,
&p_inst->dst,
&p_inst->src[0],
&p_inst->src[1]) != EOF) {
trace_queue = append_node(trace_queue,p_inst);
inst = trace_queue->current->data; // no need to explicitly cast using gcc
printf("%x %d %d %d %d\n",inst->address,inst->type, inst->dst, inst->src[0], inst->src[1]);
trace_queue->current = trace_queue->current->next;
++total_instructions;
}
The output prints me exactly what I expected, the data from the proc_tf data file.
I also forgot advance the list by setting current node to the next node, so it kept printing the same thing over and over.
Thanks.