为什么函数指针和数据指针在 C/C++ 中不兼容?

时间:2023-02-13
本文介绍了为什么函数指针和数据指针在 C/C++ 中不兼容?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

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?

解决方案

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.

这篇关于为什么函数指针和数据指针在 C/C++ 中不兼容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

上一篇:在 C/C++ 中声明指针变量的正确方法 下一篇:为什么 int 指针 '++' 递增 4 而不是 1?

相关文章

最新文章