使用C中的void *指针的缺点 [英] Disadvantages of using void* pointers in C

查看:241
本文介绍了使用C中的void *指针的缺点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有很多缺点,使用无效* 在C(内存相关,相关型,效率明智的...)。尽管他们的,我们使用他们很多关于他们提供的灵活性。

There are many drawbacks to using void * in C (memory related, type related, efficiency wise ...). In spite of them we use them a lot for the flexibility they provide.

使用列出的缺点/缺点<为code>无效* (并用C preferred解决方案 - 如果可能的话)。

List the disadvantages/drawbacks using void * (and preferred solution in C - if possible).

编辑:
请通过follwoing链接:
<一href=\"http://attractivechaos.word$p$pss.com/2008/10/02/using-void-in-generic-c-programming-may-be-inefficient/\" rel=\"nofollow\">http://attractivechaos.word$p$pss.com/2008/10/02/using-void-in-generic-c-programming-may-be-inefficient/

推荐答案

有与空指针没有效率的问题。
与空指针的唯一限制是:

There are no efficiency issues with void pointers. The only limitations with void pointers are:


  • 您不能解引用显而易见的原因,空指针

  • 的sizeof(无效)是非法的

  • 您不能执行对空指针的指针算术

但是GCC假设的sizeof(无效)为1,允许在空指针的指针算术 - 的see这里

However GCC assumes that sizeof(void) is 1 and allows pointer arithmetics on void pointers - see here

这篇关于使用C中的void *指针的缺点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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