一个宗教问题:int * i; / *或* / int * i;? [英] A religious question: int* i; /*or*/ int *i;?
问题描述
我正在阅读Kyle Loudon的_C ++ _ Pocket_Reference_,以便
审查。他使用Kernighan和Ritchie在
中使用的符号形式来声明指针(以及扩展引用)。也就是说,''*'或''&''
直接放在声明的标识符之前。 Stroustrup
一直使用替代形式在要指向的对象的类型名称之后立即放置''*''或''&''
或
引用。
我更喜欢Stroustrup'的风格,因为它似乎在语法上更准确,而且不是b $ b给人的印象是'*''或''&''在申报单中用作运营商。
我见过第三种方法是在''*''
或''&''两侧放置空格。对我而言,这简直就是模棱两可。
所以我有两个问题。首先,您更喜欢和为什么?
其次,
声明的正式语法分解是什么形式:
int * i; ?
是的,我认为这既是一个严肃的问题,也是一个诙谐的问题。 ;)
我只是好奇其他人对此有什么看法。其他什么风格
值得注意的当局使用?
-
STH
哈顿定律:" ;只有一个不可侵犯的法律
KDevelop: http:// www。 kdevelop.org SuSE: http://www.suse.com
Mozilla: http://www.mozilla.org >
Hello Steven,
On Thu,2004年8月26日02:11:22 -0400,Steven T. Hatton写道:< blockquote class =post_quotes>我更喜欢Stroustrup的风格,因为它似乎在语法上更准确,并且没有给出'*'或''&'''的印象
在声明中用作操作符。
我也更喜欢Stroutsroups的风格,但是这样做有一个陷阱。
。声明
int * i,j;
你会得到
int * i; //如期待的
int j; //一个int而不是一个指向int的指针
问候
Carsten
-
mail< AT> carsten-spiess.de
Steven T. Hatton写道:我正在阅读Kyle Loudon'的_C ++ _ Pocket_Reference_为了
审查。他使用Kernighan和Ritchie在声明指针(以及扩展引用)中使用的符号形式。也就是说,''''或''&''
直接放在声明的标识符之前。 Stroustrup
始终使用另一种形式,即在要指向或引用的对象的类型名称之后立即放置''*''或''&''
。
我更喜欢Stroustrup'的风格,因为它似乎在语法上更准确,并且没有给出''*'或''&''正在
在声明中用作操作符。
我已经看到第三种方法是在'''''或''&''两侧放置空格。对我而言,这简直就是模棱两可。
所以我有两个问题。首先,你喜欢哪个以及为什么?
第二,形式的声明的正式语法分解是什么:
int * i; ?
是的,我认为这既是一个严肃的问题,也是一个诙谐的问题。 ;)
我只是好奇别人对此有什么看法。其他
着名权威机构使用什么样的风格?
考虑一下:
int * p,i;
和
int * p,i;
i在两种情况下都是int,所以将星号放在int附近可能是
令人困惑。
另一方面,在第一种方法*中使用标识符p
这是一个指针。
所以我认为第一个是更理性正确。另外
将是第二种方法:
int * p,i,* r; ?
int * p,i,* r;
第二个看起来像我一样愚蠢。 :-)
问候,
Ioannis Vranos
http://www23.brinkster.com/noicys
Steven T. Hatton写道:
....
是的,我认为这既是一个严肃的问题,也是一个诙谐的问题。 ;)
我只是好奇别人对此有什么看法。其他
着名权威人士使用什么样的风格?
只有1种正确方法! :-)
http://tinyurl.com/4bnb7
http://groups.google.com/groups?hl=e...andrew.cmu.edu
I''m reading through Kyle Loudon''s _C++_Pocket_Reference_ for the sake of
review. He uses the notational form used by Kernighan and Ritchie in
declaring pointers (and by extension references). That is, the ''*'' or ''&''
is placed directly preceeding the identifier being declared. Stroustrup
consistently uses the alternative form of placing the ''*'' or ''&''
immediately after the type name of the object to be pointed to or
referenced.
I much prefer Stroustrup''s style because it seems to be grammatically more
accurate, and does not give the impression that the ''*'' or ''&'' is being
used as an operator in the declaration.
I have seen a third approach of putting whitespace on either side of the ''*''
or ''&''. To me this is simply equivocating non-committal.
So I have two questions about this. First which do you prefer and why?
Second, what is the formal grammatical decomposition of a declaration of
the form:
int* i; ?
Yes, I am asking this as both a serious question, and tongue-in-cheek. ;)
I''m just curious what others have to say about it. What style do other
notable authorities use?
--
STH
Hatton''s Law: "There is only One inviolable Law"
KDevelop: http://www.kdevelop.org SuSE: http://www.suse.com
Mozilla: http://www.mozilla.org
Hello Steven,
On Thu, 26 Aug 2004 02:11:22 -0400, Steven T. Hatton wrote:I much prefer Stroustrup''s style because it seems to be grammatically more
accurate, and does not give the impression that the ''*'' or ''&'' is being
used as an operator in the declaration.
I also prefer Stroutsroups style, but there is a pitfall with doing
this. Declare
int* i,j;
and you will get
int* i; // as excpected
int j; // an int and not a pointer to int
Regards
Carsten
--
mail<AT>carsten-spiess.de
Steven T. Hatton wrote:I''m reading through Kyle Loudon''s _C++_Pocket_Reference_ for the sake of
review. He uses the notational form used by Kernighan and Ritchie in
declaring pointers (and by extension references). That is, the ''*'' or ''&''
is placed directly preceeding the identifier being declared. Stroustrup
consistently uses the alternative form of placing the ''*'' or ''&''
immediately after the type name of the object to be pointed to or
referenced.
I much prefer Stroustrup''s style because it seems to be grammatically more
accurate, and does not give the impression that the ''*'' or ''&'' is being
used as an operator in the declaration.
I have seen a third approach of putting whitespace on either side of the ''*''
or ''&''. To me this is simply equivocating non-committal.
So I have two questions about this. First which do you prefer and why?
Second, what is the formal grammatical decomposition of a declaration of
the form:
int* i; ?
Yes, I am asking this as both a serious question, and tongue-in-cheek. ;)
I''m just curious what others have to say about it. What style do other
notable authorities use?
Consider this:
int *p, i;
and
int* p, i;
i in both cases is an int, so placing the asterisk close to int may be
confusing.
On the other hand, in the first approach * goes with the identifier p
which is a pointer.
So I consider the first one to be the more "rational correct". Also how
would be the second approach in the case:
int *p, i, *r; ?
int* p, i, * r;
The second looks like idiotic to me. :-)
Regards,
Ioannis Vranos
http://www23.brinkster.com/noicys
Steven T. Hatton wrote:
....
Yes, I am asking this as both a serious question, and tongue-in-cheek. ;)
I''m just curious what others have to say about it. What style do other
notable authorities use?
There is only 1 right way ! :-)
http://tinyurl.com/4bnb7
http://groups.google.com/groups?hl=e...andrew.cmu.edu
这篇关于一个宗教问题:int * i; / *或* / int * i;?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!