Sizeof算子的模拟 [英] Simulation of Sizeof operator

查看:78
本文介绍了Sizeof算子的模拟的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一个人和所有人

其中一个开发人员问我你可以实现一个用户定义的功能吗?

类似于C中的sizeof操作员编程语言" ;.

是否可以在C?

解决方案

在文章< 11 ** ********************@o13g2000cwo.googlegroups .com> ;,

sabarish< su ****** @ gmail.com> ;写道:

其中一位开发人员问我你能实现一个用户定义的功能吗?类似于C编程语言中的sizeof操作符。
是否有可能在C?




几个星期前我们详细讨论了这个问题。


快速摘要是:不,不可移植。但你可以为

机器做这个,其中NULL指针 - 表示 - 是地址0.


-

卡尔加里大学的研究员克里斯托弗·奥尔德发现,b $ b牛奶是最理性的成瘾。在所研究的几个中。


sabarish <苏****** @ gmail.com>在消息中写道

news:11 ********************** @ o13g2000cwo.googlegr oups.com ...

其中一位开发人员问我你能实现一个用户定义的功能吗?类似于C编程语言中的sizeof操作符。
是否有可能在C?




最有可能是的,但我不确定是否有任何鼻子

恶魔,可移植性问题:)。

将sizeof(type)模仿为((size_t)((type *)0 + 1))。


Alex


< blockquote>" Alexei A. Frounze" <人***** @ chat.ru>在消息中写道

news:3q ************ @ individual.net ...

" sabarish" <苏****** @ gmail.com>在消息中写道
新闻:11 ********************** @ o13g2000cwo.googlegr oups.com ...

其中一位开发人员问我你能实现一个用户定义的功能吗?类似于C编程语言中的sizeof操作员。
是否有可能在C?



很可能是的,但我不确定是否有任何鼻子恶魔,可移植性问题:)。
将sizeof(type)模仿为((size_t)((类型) *)0 + 1))。

Alex




正如Walter刚才所说,如果为NULL(或0)可能会出现问题指针

不是地址0.


Alex


Hi to one and all

one of the developer asked me "Can u implement one user defined funtion
similar to the sizeof operaor in C Programming Language".
is it possible in C ?

解决方案

In article <11**********************@o13g2000cwo.googlegroups .com>,
sabarish <su******@gmail.com> wrote:

one of the developer asked me "Can u implement one user defined funtion
similar to the sizeof operaor in C Programming Language".
is it possible in C ?



We went over this at length just a few weeks ago.

The quick summary is: No, not portably. But you can do it for
machines in which the NULL pointer -happens- to be address 0.

--
University of Calgary researcher Christopher Auld has found that
milk is the most "rational addiction" amongst the several studied.


"sabarish" <su******@gmail.com> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.com...

one of the developer asked me "Can u implement one user defined funtion
similar to the sizeof operaor in C Programming Language".
is it possible in C ?



Most probably yes, but I''m not sure whether or not there are any nasal
demons, portability issues :).
Consider sizeof(type) being mimicked as ((size_t)((type*)0+1)).

Alex


"Alexei A. Frounze" <al*****@chat.ru> wrote in message
news:3q************@individual.net...

"sabarish" <su******@gmail.com> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.com...

one of the developer asked me "Can u implement one user defined funtion
similar to the sizeof operaor in C Programming Language".
is it possible in C ?



Most probably yes, but I''m not sure whether or not there are any nasal
demons, portability issues :).
Consider sizeof(type) being mimicked as ((size_t)((type*)0+1)).

Alex



Right, as Walter just said, there can be problems if NULL (or 0) pointer
isn''t address 0.

Alex


这篇关于Sizeof算子的模拟的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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