Which machine can use (* (void (*) ()) 0) ()?

C traps and traps 2.1 I thought 0 was always an invalid address. How could he put a function in this position?

+2
source share
3 answers

It depends on the architecture.

From book:

I once spoke to someone who had a letter C program that was going to run autonomously into a small microprocessor (the answer is right here ). when this machine was switched on, the hardware would call a subroutine whose address was stored at location 0. In order to simulate the conversion of power to, we had to develop a C expression to call this subroutine explicitly. After some thought, we came up with the following:

(*(void(*)())0)(); 
+5
source

For microprocessors / microcontrollers, you have raw access to any RAM / Flash address if it is prohibited by hardware. Therefore, access to address 0 in the microprocessor is completely vaild.

+1
source

I think (* (void (*)()) 0) means that he is trying to call a function located in memory at address 0x00000000 (which is probably an invalid address)

A very similar stackoverflow question. What does this C statement mean? may I help

0
source

All Articles