这是什么? [英] What is this?
问题描述
这是什么?
(char *)&((struct aStruct *)0)
看起来它正在将包含
指针的地址转换为null,并将其转换为指向char的指针。
(实际上,从技术上讲,指向
struct aStruct开头的指针的地址,从地址0开始)。
或者,是否将指针指向null本身,并将其转换为指向char的
指针?
What is this?
( char * ) &( ( struct aStruct * ) 0 )
It looks like it''s taking the address of something that contains a
pointer to null, and casting it to a pointer to char.
(Actually, technically, the address of a pointer to the beginning of a
struct aStruct, that starts at address 0).
Or, is it taking the pointer to null itself, and casting that to a
pointer to char?
推荐答案
11月19日下午1:48 *,Eric< answer.to.newsgr ... @ nospam.comwrote:
On Nov 19, 1:48*pm, Eric <answer.to.newsgr...@nospam.comwrote:
这是什么?
(char *)*&((struct aStruct *)* 0)
What is this?
( char * ) *&( ( struct aStruct * ) *0 )
它不会起作用,因为你不能取常数
((struct aStruct *)0)的地址(&)。
It wouldn''t work, because you can''t take address (&) of the constant
(( struct aStruct * ) 0 ).
Eric写道:
Eric wrote:
>
这是什么?
(char *)&((struct aStruct *)0)
看起来它正在将包含
指针的地址转换为null,并将其转换为指向char的指针。
>
What is this?
( char * ) &( ( struct aStruct * ) 0 )
It looks like it''s taking the address of something that contains a
pointer to null, and casting it to a pointer to char.
不,它看起来像是试图获取null
指针值的地址。因此,这是违反约束的行为(6.5.3.2p1)。
No, it looks like something that attempts to take the address of a null
pointer value. As such, it''s a constraint violation (6.5.3.2p1).
在文章< kh ************** ******************@4ax.com> ;,
Eric< an ************** ***@nospam.comwrote:
In article <kh********************************@4ax.com>,
Eric <an*****************@nospam.comwrote:
>这是什么?
(char *)&((struct aStruct *) 0)
>What is this?
( char * ) &( ( struct aStruct * ) 0 )
实际上,这是一个错误。如果它是
(char *)&((struct aStruct *)0) - > x
(假设x是a结构的成员),然后它将是一个几乎合理的(虽然理论上是非便携的)模仿
offsetof()。
>
- Richard
-
请记得提及我/你留下的录音带。
As it is, it''s an error. If it were
( char * ) &( ( struct aStruct * ) 0 )->x
(assuming x is a member of the struct), then it would be an
almost-plausible (though theoretically non-portable) imitation of
offsetof().
-- Richard
--
Please remember to mention me / in tapes you leave behind.
这篇关于这是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!