This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

casting function pointer to unsigned long gives wrong result

Other Parts Discussed in Thread: MSP430F5438

I have the equivalent of:

  typedef unsigned long codeptr_t;

  void y(void) {};

  codeptr_t x = (codeptr_t) y;

The compiler accepts this with no error or warning, but actually discards the high bytes, effectively doing:

  codeptr_t x = (codeptr_t)((unsigned int) y);

This is in the context of the task scheduler of a RTOS.

Environment is MSP430F5438 on CCS Version: 5.1.1.00031

  • I'll bet you are in small code model?  At the C level, function pointers have 16 bits.

    If not, could you post a code fragment that demonstrates the problem, including the command-line options used?