Issue
This is some startup file excerpt with interrupt vectors.
#pragma DATA_SECTION(interruptVectors, ".intvects")
void (* const interruptVectors[])(void) =
{
(void (*) (void))((uint32_t)&__STACK_END),
resetISR,
nmi_ISR,
fault_ISR,
... /* More interrupt vectors */
void (* const interruptVectors[])(void)
- is an array of function pointers that must contain function names, but I can't understand the (void (*) (void))((uint32_t)&__STACK_END)
syntax.
(void (*) (void))
looks like a pointer to a function that returns nothing, without arguments and doesn't have any name. Is it possible?
(uint32_t)&__STACK_END
is a pointer. And why are the function pointer and pointer together?
Solution
This looks like the interrupt vector table for an ARM processor or similar. The interrupt vector table contains the addresses of interrupt handlers, so it is essentially an array of function pointers.
The first entry of this table is the initialization value for the stack pointer. It's obviously not a function pointer, but a data pointer, so some type conversion is needed. Not because the processor cares about types, but because C does.
So &__STACK_END
is presumable some pointer type which points to a data address at the end of the stack. This is then converted to a plain 32-bit number, and finally converted to a function pointer.
It might have been possible to skip the first cast to uint32_t
and cast directly from a data pointer to a function pointer, if the compiler supported it as an extension. But strictly speaking, in the C standard conversion from a data pointer directly to a function pointer is not legal, and cast to interger is necessary.
There are also additional implemetation defined issues programmer must consider for this kind conversion to work: sizes of types and alignments must be compatible, there must not be trap representations, etc. This is all normal when working with code that is close to hardware.
Answered By - user694733 Answer Checked By - Cary Denson (PHPFixing Admin)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.