空值 [英] NULL

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

问题描述

嗨组,

填写我的Windows(tm)结构时,我使用

NULL表示对象指针,0表示int,浮点数等。

我发现这个编译:


int a = NULL;

float b = NULL;

等。


有效吗?


-X

解决方案

< blockquote>代理Mulder写道:

嗨组,
当填写我的Windows(tm)结构时,我使用
NULL作为对象指针,0作为整数,浮动等
我发现这个编译:

int a = NULL;
浮动b = NULL;


这有效吗?




NULL几乎可以肯定定义为

#define NULL 0


那为什么不呢?它只是替换文字。




Dimitris Kamenopoulos < DK ********* @ cslab.ece.ntua.gr>在消息中写道

news:bj *********** @ ulysses.noc.ntua.gr ...

代理人Mulder写道:

嗨组,
当我填写我的Windows(tm)结构时,我使用
NULL表示对象指针,0表示整数,浮点数等。
我发现这个编译:

int a = NULL;
浮动b = NULL;


这有效吗?



NULL几乎可以肯定定义为
#define NULL 0

为什么不呢?它只是替代文本。




我认为这说明了NULL浪费的时间。它假装是一个特殊的指针值,但实际上它只是零。不要假装,使用零。


john




"代理Mulder" < MB ******************* @ home.nl>在消息新闻中写道:bj ********** @ news3.tilbu1.nb.home.nl ...

嗨组,
填写我的Windows时( tm)结构,我使用
NULL表示对象指针,0表示int,浮点数等。
我发现这个编译:

int a = NULL;
float b = NULL;
等。



它在C ++中有效,但有点傻。对于整数常量表达式,C ++要求NULL为宏

。评估为零。


但请注意,它在C中不是一个好主意C允许(愚蠢地在我的

意见中)在值0上添加(void *)强制转换。这不允许

赋值给数字类型。


Hi group,
When filling in my Windows(tm) structs, I use
NULL for object pointers and 0 for ints, floats etc.
I found out that this compiles:

int a=NULL;
float b=NULL;
etc.

Is that valid?

-X

解决方案

Agent Mulder wrote:

Hi group,
When filling in my Windows(tm) structs, I use
NULL for object pointers and 0 for ints, floats etc.
I found out that this compiles:

int a=NULL;
float b=NULL;
etc.

Is that valid?



NULL is almost certainly defined as
#define NULL 0

So why not? It''s just substituted text.



"Dimitris Kamenopoulos" <dk*********@cslab.ece.ntua.gr> wrote in message
news:bj***********@ulysses.noc.ntua.gr...

Agent Mulder wrote:

Hi group,
When filling in my Windows(tm) structs, I use
NULL for object pointers and 0 for ints, floats etc.
I found out that this compiles:

int a=NULL;
float b=NULL;
etc.

Is that valid?



NULL is almost certainly defined as
#define NULL 0

So why not? It''s just substituted text.



I think this illustrates what a waste of time NULL is. Its pretending to be
a special pointer value, but really it just zero. Don''t pretend, use zero.

john



"Agent Mulder" <mb*******************@home.nl> wrote in message news:bj**********@news3.tilbu1.nb.home.nl...

Hi group,
When filling in my Windows(tm) structs, I use
NULL for object pointers and 0 for ints, floats etc.
I found out that this compiles:

int a=NULL;
float b=NULL;
etc.


It''s valid in C++, but kind of silly. C++ requires NULL to be a macro
for an integer constant expression evaluating to zero.

Note however, that it''s not a good idea in C. C allows (stupidly in my
opinion) the addition of a (void*) cast on the value 0. This won''t allow
assignment to numeric types.


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

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