编译器有多愚蠢?! [英] How stupid can a compiler be?!

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

问题描述

今天我写了一个返回std :: ostringstream的函数。按价值。


我用G ++编译它。


它在运行时和关闭时抛出异常。


所以我看一下代码,我看起来,我看起来......


我忘了在上述功能中输入return语句,即。

它没有退货声明。


这怎么编译?!标准是否允许允许这要编译吗?


我的函数究竟会返回什么,一个无名的默认对象,即

std :: ostringstream()?


-JKop

解决方案

JKop< NU ** @ NULL.NULL>写在

新闻:Mb ******************* @ news.indigo.ie:

今天我写了一个返回std :: ostringstream的函数。通过
值。

我用G ++编译它。

它在运行时和关闭时抛出异常。

所以我看看代码,我看起来,我看起来......

我忘了把上述功能中的返回声明,即
。它没有退货声明。


要扭转标题......程序员可以做多么愚蠢,请声明一个

函数而不用费心去返回任何东西? ;

这怎么编译?!标准是否允许允许这要编译吗?

我的函数究竟会返回什么,一个无名的默认对象,即。
std :: ostringstream()?




谁知道(编译器编写者除外)。但是,我建议你打开尽可能多的编译诊断程序(比如-Wall)。我知道g ++会警告你控制到达非虚空

函数的结尾。


要转换标题....程序员
多么愚蠢,请声明一个函数而不用费心去返回任何东西?



我把所有注意力集中在准备好物品

要退回,然后我只是*忘了*输入:


返回blah;

....我认为可能还有其他问题需要用宏来做

(我有windows.h包括在内我得到了所有

各种奇怪的编译器错误,可能有些宏是

与函数,变量,类的名称相互关联

我已经宣布了。


MACROS将死。

-JKop


JKop写道:

...我认为可能还有其他一些问题需要用宏来做(我已经包含了windows.h)。我得到了所有各种奇怪的编译器错误,可能有些宏与函数,变量,类的名称相互关联
我已经声明了。



您是否安装了最新的MINGW包?如果是,这些是编译器

选项,这些选项很好用:


-std = c ++ 98 -pedantic-errors -Wall -fexpensive-优化-O3

-ffloat-store -mcpu = pentiumpro


-

Ioannis Vranos
http://www23.brinkster.com/noicys


Today I wrote a function that returned an "std::ostringstream" by value.

I compiled it with G++.

It was throwing exceptions at run-time and closing.

So I look through the code, and I look and I look...

I forgot to put in the return statement in the aforementioned funtion, ie.
it had no return statement.

How the hell does this compile?! Does the Standard "allow" this to compile?

What exactly would my function return, a nameless default object, ie.
std::ostringstream()?

-JKop

解决方案

JKop <NU**@NULL.NULL> wrote in
news:Mb*******************@news.indigo.ie:

Today I wrote a function that returned an "std::ostringstream" by
value.

I compiled it with G++.

It was throwing exceptions at run-time and closing.

So I look through the code, and I look and I look...

I forgot to put in the return statement in the aforementioned funtion,
ie. it had no return statement.
To turn around the title.... "How silly can a programmer be, do declare a
function and not bother to return anything?"
How the hell does this compile?! Does the Standard "allow" this to
compile?

What exactly would my function return, a nameless default object, ie.
std::ostringstream()?



Who knows (other than the compiler writers). However, I''d suggest that you
turn on as many of the compilier diagnostics that you can (like -Wall). I
know that g++ will warn you about control reaching the end of a non-void
function.


To turn around the title.... "How silly can a programmer be, do declare a function and not bother to return anything?"



I was focusing all my attention on making the object ready
to be returned, then I simply *forgot* to type:

return blah;
....I think there may be some other problem though to do
with macros (I''ve got "windows.h" included). I''m get all
sorts of weird compiler errors, possibly some macros are
inteferring with the names of functions, variables, classes
I''ve declare.

MACROS WILL DIE.
-JKop


JKop wrote:

...I think there may be some other problem though to do
with macros (I''ve got "windows.h" included). I''m get all
sorts of weird compiler errors, possibly some macros are
inteferring with the names of functions, variables, classes
I''ve declare.

MACROS WILL DIE.


Did you install the latest MINGW package? If yes, these are the compiler
options that are good to use:

-std=c++98 -pedantic-errors -Wall -fexpensive-optimizations -O3
-ffloat-store -mcpu=pentiumpro

--
Ioannis Vranos

http://www23.brinkster.com/noicys


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

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