Why Function and Data Pointers are Incompatible in C/C
While converting between data pointers and function pointers is generally successful on most platforms, compatibility is not guaranteed. This raises the question: shouldn't the compatibility be straightforward given that both point to memory addresses?
The explanation lies in the architecture employed by the computing system. C/C does not restrict itself to specific architectures and allows for flexibility in how memory is managed. Some architectures, like the Harvard architecture, maintain separate memory spaces for code and data. In contrast, Von Neumann architectures store code and data in the same memory.
In the case of Von Neumann architectures, where code and data reside in the same space, converting between a function pointer and a data pointer may be possible. However, the actual compatibility cannot be taken for granted. In systems that differentiate between the two memory spaces, such as Harvard architectures, the conversion will fail.
The above is the detailed content of Why Aren't Function and Data Pointers Always Compatible in C/C ?. For more information, please follow other related articles on the PHP Chinese website!