为什么函数指针和数据指针在C / C ++不兼容? [英] Why are function pointers and data pointers incompatible in C/C++?

查看:136
本文介绍了为什么函数指针和数据指针在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?

推荐答案

这是体系不存储code和数据在相同的内存。与哈佛结构,code和数据存储在完全不同的记忆。大多数架构是冯诺依曼架构与code和数据在相同的内存,但C不会只局限于只有某些类型的架构,如果在所有可能的。

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 ++不兼容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆