可疑的编译器警告 [英] Questionable compiler warning

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

问题描述




请考虑以下计划。


class T

{

int b,a;

T(int a,int b):a(a),b(b){}

};


g ++ -Wall -c test.cc产生以下警告。


test.cc:在构造函数`T :: T(int,int)''中:

test.cc:3:Warnung:`T :: a''将在

test.cc:3之后初始化:Warnung:`int T :: b ''

test.cc:4:Warnung:在这里初始化时

显然,g ++喜欢初始化顺序为

与声明命令对应的

变量。有没有人知道/为什么它是关键的

他们有相同的订单?


感谢您的帮助。

此致,


Thomas

Hi

Consider the following program.

class T
{
int b, a;
T(int a, int b) : a(a), b(b) {}
};

g++ -Wall -c test.cc produces the following warning.

test.cc: In constructor `T::T(int, int)'':
test.cc:3: Warnung: `T::a'' will be initialized after
test.cc:3: Warnung: `int T::b''
test.cc:4: Warnung: when initialized here
Obviously, g++ likes the initialization order to be
the same as the declaration order of the corresponding
variables. Does anyone know whether/why it is critical
for them to have the same order?

Thanks for your help.
Regards,

Thomas

推荐答案



" Thomas Heinz" <第********* @ gmx.net>在留言中写道

新闻:cc ************ @ hades.rz.uni-saarland.de ...

"Thomas Heinz" <th*********@gmx.net> wrote in message
news:cc************@hades.rz.uni-saarland.de...


考虑以下程序。

类T
{b> a b,a;
T(int a,int b):a( a),b(b){}
};

g ++ -Wall -c test.cc产生以下警告。

test.cc:在构造函数中`T :: T(int,int)'':
test.cc:3:Warnung:`T :: a''将在
test.cc:3之后初始化:Warnung:`int T :: b''
test.cc:4:Warnung:在这里初始化时

显然,g ++喜欢初始化顺序与声明顺序相同相应的变量。有没有人知道/为什么它们对于他们有相同的订单是至关重要的?
Hi

Consider the following program.

class T
{
int b, a;
T(int a, int b) : a(a), b(b) {}
};

g++ -Wall -c test.cc produces the following warning.

test.cc: In constructor `T::T(int, int)'':
test.cc:3: Warnung: `T::a'' will be initialized after
test.cc:3: Warnung: `int T::b''
test.cc:4: Warnung: when initialized here
Obviously, g++ likes the initialization order to be
the same as the declaration order of the corresponding
variables. Does anyone know whether/why it is critical
for them to have the same order?




这不是,但有些人错误地认为初始化的顺序是&b
与初始化列表中的顺序相同。所以我想这个警告的原因只是为了确保人们不会犯这个错误。


john



It isn''t, but some people wrongly assume that the order of initalisation is
the same as the order in the initialisation list. So I would imagine the
reason for the warning is just to make sure people don''t make that mistake.

john


你好约翰


您写道:
Hi John

You wrote:
这不是,但有些人错误地认为初始化的顺序与初始化列表中的顺序相同。因此,我认为警告的原因只是为了确保人们不会犯这个错误。
It isn''t, but some people wrongly assume that the order of initalisation is
the same as the order in the initialisation list. So I would imagine the
reason for the warning is just to make sure people don''t make that mistake.




有一个误解。我的问题应该是:


显然,g ++喜欢初始化顺序为

与相应的声明顺序相同

成员。 (不是init。列表中的变量)。


但是,我认为通过某种方式修复初始化顺序

的一个原因是只能是一个破坏

订单。

问候,


Thomas



There is a misunderstanding. My question should rather be:

"Obviously, g++ likes the initialization order to be
the same as the declaration order of the corresponding
members." (not variables in the init. list).

However, I think one reason why the initialization order is
fixed by some means is that there can only be one destruction
order.
Regards,

Thomas


Thomas Heinz写道:
Thomas Heinz wrote:
嗨John

你写道:
Hi John

You wrote:
这不是,但有些人错误地认为
初始化的顺序与初始化列表中的顺序相同。所以我想象警告的原因只是为了确保人们不会犯这个错误。
It isn''t, but some people wrongly assume that the order of
initalisation is
the same as the order in the initialisation list. So I would imagine the
reason for the warning is just to make sure people don''t make that
mistake.



有一个误解。我的问题应该是:

显然,g ++喜欢初始化顺序与相应
成员的声明顺序相同。 (不是init。列表中的变量)。

但是,我认为通过某种方式修复初始化顺序的一个原因是只能有一个销毁命令。


There is a misunderstanding. My question should rather be:

"Obviously, g++ likes the initialization order to be
the same as the declaration order of the corresponding
members." (not variables in the init. list).

However, I think one reason why the initialization order is
fixed by some means is that there can only be one destruction
order.




是的,但这不是你陈述的本质,也不是约翰回复的本质

。警告的原因是_remind_用户

初始化的订单将与声明相同,

而不是初始订单的顺序清单。


这不是g ++喜欢它是相同的,它更符合g ++

试图阻止用户犯错误。如果g ++ _liked_具体是

,那么它可能会发出错误而不是警告。


很抱歉对话,只是想到了我要添加



Yes, but that''s not the essence of your statement, nor is it the essence
of John''s reply. The reason for the warning is to _remind_ the user that
the order [of initialisation] is going to be the same as the declaration,
and not the order of initialisers in the list.

It''s not that g++ "likes" it to be the same, it''s more in line with g++
trying to keep the user from making the mistake. If g++ _liked_ it to be
specific, then it would probably issue an error instead of a warning.

Sorry to butt in on the conversation, just thought I''d add my


这篇关于可疑的编译器警告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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