Is there a way using C51/Cx51 to easily switch based on the memory type of a generic pointer? So far, the best thing I have is:
void my_func(void * ptr) { switch(*(uint8_t *)&ptr) { case 0x00: // do data/idata-specific stuff case 0x01: // do xdata-specific stuff case 0xff: // do code-specific stuff default: // do error-handling } }
OK cool, thanks =)
printf() can do that with the "%p" format specification:
http://www.keil.com/support/man/docs/c51/c51_printf.htm
But that's probably not what you are after. Since the format of a generic pointer is specified in the manual, I think it's safe to do it the way your did.
No, the switch operand is the pointer; or rather, just the first byte of the generic pointer representing the memory type.
It doesn't have to be a switch statement, I'm just wondering if there is a built-in way in Keil to determine the memory type of a generic pointer at run time -- if someone passes me an XDATA pointer, do this; if they pass me a CODE pointer, do that.
what on earth are you doing??? the switch variable must have the case operands defined. there can be no variance.
Erik
View all questions in Keil forum