| |||||
Technical Support Support Resources
Product Information | C166: CASTING A VARIABLE ON THE STACK TO A CODE POINTERInformation in this article applies to:
SYMPTOMSI have the following function declared:
void testcode (void)
{
unsigned int buf [100]; void (far *func) (void);
xmemcpy (mycode, buf, 100);
func = (void *) buf;
(*func) ();
}
I want to get a far function pointer to buf and then to call it. The following code doesn't convert the variable address to a function pointer correctly. It appears that the lower 14 bits of the address are loaded into the lower word of the address and the contents of the DPP register are loaded into the upper 16 bits. CAUSEThat is exactly correct. The reason is because far pointers to variables are treated differently than far pointers to program code. RESOLUTIONChange the assignment of buf to func to the following: (unsigned long) func = (unsigned long) buf; and the above program will work correctly. MORE INFORMATION
Last Reviewed: Friday, July 15, 2005 | ||||
| |||||