恼人的编译器警告 [英] Annoying compiler warning

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

问题描述




我一直试图在我的代码中使用一些创造性的替代习语用于无限的

循环,而不是用于(;; ;)和while(1) - 这个

可能是一个很好的有趣的复活节彩蛋,可用于任何未来的维护

程序员!


我的一个想法是这样的:


无符号u = SHRT_MAX<< 2; //误导初始化 - 开球嘻嘻!

while(++ u> = 0)

{

//循环

}


不幸的是,编译器给出了一个警告,而不是
破坏了乐趣...编译器是否必须提供诊断在这里,和

任何人都可以想到一种使用相同基本想法的方法,但没有

产生警告?

Hi,

I have been trying to use some inventive alternative idioms for infinite
loops in my code, rather than the same old for(;;) and while(1) - this
could be a nice amusing Easter-egg for any future maintenance
programmers!

One of my ideas was this:

unsigned u = SHRT_MAX << 2; // misleading initialization - tee hee!
while(++u>=0)
{
// loop
}

Unfortunately, the compiler gives a warning for this, which rather
spoils the fun... does the compiler have to give a diagnostic here, and
can anyone think of a way of using the same basic idea but without
generating a warning?

推荐答案

Bob写道:
Bob wrote:

>




我一直试图在我的代码中使用一些创造性的替代

成语来获得无限的

循环,而不是(;;)和(1) - 这个

可能是一个很有趣的复活节彩蛋,可用于任何未来的维护

程序员!


我的一个想法是这样的:


无符号u = SHRT_MAX<< 2; //误导初始化 - 开球嘻嘻!

while(++ u> = 0)

{

//循环

}


不幸的是,编译器给出了一个警告,相反

破坏了这个乐趣...

编译器必须在这里给出一个诊断,
>
Hi,

I have been trying to use some inventive alternative
idioms for infinite
loops in my code, rather than the same old for(;;) and while(1) - this
could be a nice amusing Easter-egg for any future maintenance
programmers!

One of my ideas was this:

unsigned u = SHRT_MAX << 2; // misleading initialization - tee hee!
while(++u>=0)
{
// loop
}

Unfortunately, the compiler gives a warning for this, which rather
spoils the fun...
does the compiler have to give a diagnostic here,



如果确实如此,我可以查一查。

If it did, I could look it up.


并且任何人都可以想到使用相同的基本想法但没有产生警告的方式


and can anyone think of a way
of using the same basic idea but without generating a warning?



如何抑制身份不明的警告?

这不是一个坏事。


unsigned u = SHRT_MAX / 1000;

while( - u> = 0u)

{

// loop

}


-

pete

How to suppress an unidentified warning?
That''s not a bad one.

unsigned u = SHRT_MAX / 1000;
while(--u >= 0u)
{
// loop
}

--
pete


Bob写道:
Bob wrote:




我一直在尝试使用一些创造性的替代习语来获得无限的

循环代码,而不是(;;)和while(1)相同的旧代码 - 这个

可能是一个非常有趣的复活节彩蛋,可用于任何未来的维护

程序员!


我的一个想法是这样的:


无符号u = SHRT_MAX<< 2; //误导初始化 - 开球嘻嘻!

while(++ u> = 0)

{

//循环

}


不幸的是,编译器给出了一个警告,而不是
破坏了乐趣...编译器是否必须提供诊断在这里,和

有人能想到一种使用相同基本想法的方法,但没有

产生警告吗?
Hi,

I have been trying to use some inventive alternative idioms for infinite
loops in my code, rather than the same old for(;;) and while(1) - this
could be a nice amusing Easter-egg for any future maintenance
programmers!

One of my ideas was this:

unsigned u = SHRT_MAX << 2; // misleading initialization - tee hee!
while(++u>=0)
{
// loop
}

Unfortunately, the compiler gives a warning for this, which rather
spoils the fun... does the compiler have to give a diagnostic here, and
can anyone think of a way of using the same basic idea but without
generating a warning?



你从编译器得到什么信息?


为我工作的#include< limits.h>

What message do you get from the compiler ?

Works for me with #include <limits.h>


Bob写道:
Bob wrote:

>




我一直在尝试使用在我的代码中有一些创造性的替代成语,用于无限的

循环,而不是用于(;;)和while(1)的同一个 - 这个

可能是一个很有趣的复活节-egg用于任何未来的维护

程序员!


我的一个想法是:


unsigned u = SHRT_MA X << 2; //误导初始化 - 开球嘻嘻!

while(++ u> = 0)

{

//循环

}


不幸的是,编译器给出了一个警告,相反

破坏了这个乐趣...

编译器是否必须在此处进行诊断,并且

是否有人可以想到使用相同基本思路但没有

生成警告的方法?
>
Hi,

I have been trying to use some inventive alternative idioms for infinite
loops in my code, rather than the same old for(;;) and while(1) - this
could be a nice amusing Easter-egg for any future maintenance
programmers!

One of my ideas was this:

unsigned u = SHRT_MAX << 2; // misleading initialization - tee hee!
while(++u>=0)
{
// loop
}

Unfortunately, the compiler gives a warning for this, which rather
spoils the fun...
does the compiler have to give a diagnostic here, and
can anyone think of a way of using the same basic idea but without
generating a warning?



unsigned u;


for(u = 1 / *或任何奇数* /; u ++ 0u; ++ u)

{

//循环

}


-

pete

unsigned u;

for (u = 1 /* or any odd number */ ; u++ 0u; ++u)
{
// loop
}

--
pete


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

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