null函数指针? [英] null function pointer?

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

问题描述

似乎,为了确保指针不指向对象/函数,

NULL(或简单地说0)对于两种指针都是足够好的,数据指针

和函数指针按照6.3.2.3:


3一个整数常量表达式,值为0,或者这样的表达式

cast键入void *,称为空指针常量.55)

如果将空指针常量转换为指针类型,则生成

指针,称为空指针,保证比较不等于指向任何对象或函数的

指针。

4将空指针转换为另一个指针类型会产生空指针

那种类型。

任何两个空指针都应该相等。


这是一个愚蠢的问题,但比较如何数据到函数指针?

空函数指针应该比较等于null数据指针,对,

错了?没有不同的指针位代表在这里产生问题

或者它们是通过铸造解决的还是这不是真的

指定/定义?


Alex

解决方案

> 3一个整数常量表达式,其值为0,或者这样的表达式

强制转换为类型void *,称为空指针常量.55
如果将空指针常量转换为指针类型,则生成的指针(称为空指针)保证比较不等于指向任何对象或函数的指针。

4将空指针转换为另一种指针类型会产生该类型的空指针。
任意两个空指针应该相等。

这是一个愚蠢的问题,但如何将数据与函数指针进行比较?


数据指针和函数指针通常具有不同的大小。

例如,middle和紧凑的 i386上的内存型号为16位

另一个有反向)。

空函数指针应该比较等于空数据指针,对,
错了?


我不认为你应该做这样的比较。它比使用空指针和

a struct(NOT struct pointer,struct)几乎有意义(但不完全)。

指针没有不同的位表示在这里产生问题或者它们是通过铸造解决的还是这不是真的指定/定义?




整个操作没有任何意义,特别是当

指针都不为空时。删除该程序将是最好的定义

行为。


Gordon L. Burditt


< blockquote> Alexei A. Frounze写道:

似乎,为了确保指针不指向一个对象/函数,
NULL(或简单地说0)就足够了两种指针,数据指针和函数指针按照6.3.2.3:

3一个整数常量表达式,值为0,或者这样的表达式
强制转换为void *,被称为空指针常量.55)如果将空指针常量转换为指针类型,则生成的指针(称为空指针)保证比较不等于
指向任何对象或函数的指针。

4将空指针转换为另一种指针类型会产生该类型的空指针。
任何两个空指针都应该相等。

这是一个愚蠢的问题,但如何将数据与func进行比较指针?
Null函数指针应该比较等于null数据指针,对吧,
错了?没有不同的指针位表示在这里产生问题或者它们是通过铸造解决的还是这不是真的
指定/定义?



什么是你问?是否


if((char *)0 ==(char *)(void(*)())0){

S

}否则{

T

}


应该始终执行S?


谁在乎? :-)


S.


" Gordon Burditt" <去*********** @ burditt.org>在消息中写道

新闻:11 ************* @ corp.supernews.com ...

3一个整数常量表达式,其值为0,或者这样的表达式转换为类型void *,称为空指针常量.55)如果将空指针常量转换为指针类型,结果
指针,称为空指针,保证比较不等于指向任何对象或函数的指针。

4将空指针转换为另一个指针类型产生该类型的null
指针。
任何两个空指针都应该相等。

这是一个愚蠢的问题,但如何将数据与函数
指针进行比较?


数据指针和函数指针通常具有不同的大小。
例如,中间和中间。和紧凑的 i386上的内存模型采用16位
模式。 (一个有16位数据指针和32位函数指针,另一个有反向)。




对,我知道。

空函数指针应该比较等于null数据指针,对,错误?



我认为你不应该做这样的比较。它几乎没有(但不完全)将空指针与结构(NOT结构指针,结构)进行比较。

Doesn''这些指针的不同位表示会产生问题吗?或者它们是通过强制转换来解决的,还是指定/定义的?



整个操作没有没有任何意义,特别是当
指针都不为空时。删除程序将是最好定义的行为。




我知道,这就是我写* stupid * question的原因。 :)它和写作一样愚蠢

SLIPPERY WHEN WET在靠近水边的银行。

但仍然无效* p = NULL和void(f *)()= NULL都是空指针,符合

标准和根据标准,这样的指针应该比较相等...当他们中的一个不是空指针时,他们比较等于
?我只是好奇。

或者我从标准中要求太多了? :)


Alex


Seems like, to make sure that a pointer doesn''t point to an object/function,
NULL (or simply 0) is good enough for both kind of pointers, data pointers
and function pointers as per 6.3.2.3:

3 An integer constant expression with the value 0, or such an expression
cast to type void *, is called a null pointer constant.55)
If a null pointer constant is converted to a pointer type, the resulting
pointer, called a null pointer, is guaranteed to compare unequal to a
pointer to any object or function.

4 Conversion of a null pointer to another pointer type yields a null pointer
of that type.
Any two null pointers shall compare equal.

It''s a stupid question, but how about comparing data to function pointers?
Null function pointer should compare equal to null data pointer, right,
wrong? Doesn''t different bit representation of the pointers make problems
here or are they solved through casting or is this not really
specified/defined?

Alex

解决方案

>3 An integer constant expression with the value 0, or such an expression

cast to type void *, is called a null pointer constant.55)
If a null pointer constant is converted to a pointer type, the resulting
pointer, called a null pointer, is guaranteed to compare unequal to a
pointer to any object or function.

4 Conversion of a null pointer to another pointer type yields a null pointer
of that type.
Any two null pointers shall compare equal.

It''s a stupid question, but how about comparing data to function pointers?
data pointers and function pointers are often of different sizes.
For example, "middle" and "compact" memory models on i386 in 16-bit
mode. (one has 16-bit data pointers and 32-bit function pointers,
the other has the reverse).
Null function pointer should compare equal to null data pointer, right,
wrong?
I don''t think you should do such a comparison. It makes almost
(but not quite) as much sense as comparing a null pointer to
a struct (NOT struct pointer, struct).
Doesn''t different bit representation of the pointers make problems
here or are they solved through casting or is this not really
specified/defined?



The whole operation doesn''t make any sense, particularly when neither
pointer is null. Deletion of the program would be the best defined
behavior to establish.

Gordon L. Burditt


Alexei A. Frounze wrote:

Seems like, to make sure that a pointer doesn''t point to an object/function,
NULL (or simply 0) is good enough for both kind of pointers, data pointers
and function pointers as per 6.3.2.3:

3 An integer constant expression with the value 0, or such an expression
cast to type void *, is called a null pointer constant.55)
If a null pointer constant is converted to a pointer type, the resulting
pointer, called a null pointer, is guaranteed to compare unequal to a
pointer to any object or function.

4 Conversion of a null pointer to another pointer type yields a null pointer
of that type.
Any two null pointers shall compare equal.

It''s a stupid question, but how about comparing data to function pointers?
Null function pointer should compare equal to null data pointer, right,
wrong? Doesn''t different bit representation of the pointers make problems
here or are they solved through casting or is this not really
specified/defined?


What are you asking? Whether

if ((char*) 0 == (char*) (void (*)()) 0) {
S
} else {
T
}

should always execute S?

Who cares? :-)

S.


"Gordon Burditt" <go***********@burditt.org> wrote in message
news:11*************@corp.supernews.com...

3 An integer constant expression with the value 0, or such an expression
cast to type void *, is called a null pointer constant.55)
If a null pointer constant is converted to a pointer type, the resulting
pointer, called a null pointer, is guaranteed to compare unequal to a
pointer to any object or function.

4 Conversion of a null pointer to another pointer type yields a null pointerof that type.
Any two null pointers shall compare equal.

It''s a stupid question, but how about comparing data to function pointers?


data pointers and function pointers are often of different sizes.
For example, "middle" and "compact" memory models on i386 in 16-bit
mode. (one has 16-bit data pointers and 32-bit function pointers,
the other has the reverse).



Right, and I know that.
Null function pointer should compare equal to null data pointer, right,
wrong?



I don''t think you should do such a comparison. It makes almost
(but not quite) as much sense as comparing a null pointer to
a struct (NOT struct pointer, struct).

Doesn''t different bit representation of the pointers make problems
here or are they solved through casting or is this not really
specified/defined?



The whole operation doesn''t make any sense, particularly when neither
pointer is null. Deletion of the program would be the best defined
behavior to establish.



I know, that''s why I wrote "*stupid* question" :) It''s as stupid as writing
"SLIPPERY WHEN WET" on the bank near the water.
But still both void*p=NULL and void (f*)()=NULL are null pointers as per the
standard and as per the standard such pointers should compare equal... Can
they compare equal when one of them isn''t a null pointer? I''m just curious.
Or am I asking too much from the standard? :)

Alex


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

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