I just wrote a simple memory dump routine declared as follows: void hexdump(U16 start_address, U16 count, bit code_memory); The idea is to use <code_memory> to select between dumping from XRAM (=0) or code memory (=1). Inside the routine two pointers are declared: U8 xdata *xram_pointer; U8 code *code_pointer; And initialized (could be done in one shot): xram_pointer = (U8 xdata *) start_address; code_pointer = (U8 code *) start_address; With this in place the output look decides which pointer to use based on <code_memory>, builds the strings using sprintf, and outputs with printf one line at a time. A couple of questions: 1- "U16 start_address" is this the best way to declare this argument? 2- Is there a way to do this using a single pointer (or "start_address") within the function? Maybe, define a void pointer and then cast it into either XRAM or code? Thanks.
How do you propose to let a function like printf know whether to go to xdata or code space? That's exactly what's generic about generic pointers: they contain an extra byte to signal this difference. You may want to think of a generic pointer as a data type like
struct generic_pointer { U8 memory_class; union { void code *c; void xdata *x; void data *d; void idata *i; } ptr; };
printf(" %s", generic_pointer);