Why are function pointers and data pointers incompatible in C/C++?

gexicide picture gexicide · Sep 10, 2012 · Viewed 13.1k times · Source

I have read that converting a function pointer to a data pointer and vice versa works on most platforms but is not guaranteed to work. Why is this the case? Shouldn't both be simply addresses into main memory and therefore be compatible?

Answer

Dirk Holsopple picture Dirk Holsopple · Sep 10, 2012

An architecture doesn't have to store code and data in the same memory. With a Harvard architecture, code and data are stored in completely different memory. Most architectures are Von Neumann architectures with code and data in the same memory but C doesn't limit itself to only certain types of architectures if at all possible.