VC ++ 5.0运行与VC ++ 2003不同 [英] VC++ 5.0 runs this different then VC++2003

查看:80
本文介绍了VC ++ 5.0运行与VC ++ 2003不同的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,


我在VC ++ 5.0出现时编写了一个程序,当在VC ++ 2003中使用这个

程序时,我得到了垃圾。我能够通过可以查看数据的代码让程序运行

。由于每个对象都是新的,因此
应该没有要显示的数据。下面是一些在VC ++中运行干净的代码

5.0和VC ++ 2003中有垃圾。


//重现垃圾

#include< iostream>


使用std :: cout;


使用std :: endl;


class Repro


{


私人:


char wd [10];


struct


{


char word [10];


} st;


public:


void View();


};


无效Repro ::查看()


{


cout<< word << st.word<< endl;


cout<< wd << wd<<结束;


}


int main()


{


Repro a;


a.View();


返回0;


}


问候,

杰夫

-

它好多了发布代码然后永远不会发布

Hello,

I wrote a program way back when VC++ 5.0 was around and when using this
program in VC++ 2003 I get garbage. I was able to let the program run
through code that would view the data. Since each object is new there
should be no data to show. Here is some code that would run clean in VC++
5.0 and in VC++ 2003 there is garbage.

//Reproduce Garbage

#include <iostream>

using std::cout;

using std::endl;

class Repro

{

private:

char wd[10];

struct

{

char word[10];

}st;

public:

void View();

};

void Repro::View()

{

cout << "word " << st.word << endl;

cout << "wd " << wd << endl;

}

int main()

{

Repro a;

a.View();

return 0;

}

Regards,
Jeff
--
It is far better to post code then to never have posted

推荐答案

Jeffrey Baker写道:
Jeffrey Baker wrote:
你好,

当VC ++ 5.0出现时,我写了一个程序,当在VC ++ 2003中使用这个程序时,我得到了垃圾。我能够让程序通过可以查看数据的代码运行。由于每个对象都是新的,因此
应该没有数据显示。下面是一些在VC ++中运行干净的代码,在VC ++ 2003中有垃圾。

//重现垃圾

#include< iostream>

使用std :: cout;

使用std :: endl;

类Repro

{

私人:

char wd [10];

struct

{char / word
char word [10] ];

} st;

公开:

无视图();

};

void Repro ::查看()



cout<< word << st.word<< endl;

cout<< wd << wd<< endl;

}
int main()



Repro a;
a.View();

返回0;

}

问候,
杰夫
-
Hello,

I wrote a program way back when VC++ 5.0 was around and when using this
program in VC++ 2003 I get garbage. I was able to let the program run
through code that would view the data. Since each object is new there
should be no data to show. Here is some code that would run clean in VC++
5.0 and in VC++ 2003 there is garbage.

//Reproduce Garbage

#include <iostream>

using std::cout;

using std::endl;

class Repro

{

private:

char wd[10];

struct

{

char word[10];

}st;

public:

void View();

};

void Repro::View()

{

cout << "word " << st.word << endl;

cout << "wd " << wd << endl;

}

int main()

{

Repro a;

a.View();

return 0;

}

Regards,
Jeff
--
It is far better to post code then to never have posted




No.每个数组都是未初始化的,所以行为是未定义的。它可能

做一些好事(例如,什么都没有);它可能会做坏事。还有

真的不知道。


干杯! --M



No. Each array is uninitialized, so the behavior is undefined. It might
do something nice (e.g., nothing); it might do something bad. There''s
really no telling.

Cheers! --M


Jeffrey Baker写道:
Jeffrey Baker wrote:
当VC ++ 5.0出现并使用时,我写了一个程序回来这个程序在VC ++ 2003中我得到了垃圾。我能够让
程序运行可以查看数据的代码。由于每个对象都是新的,因此不应显示任何数据。这里有一些代码可以在VC ++ 5.0中运行干净,在VC ++ 2003中有垃圾。

//重现垃圾

#include< iostream>

使用std :: cout;

使用std :: endl;

类Repro

{

私人:

char wd [10];

struct

{char / word
char word [10] ];

} st;

公开:

无视图();

};

void Repro ::查看()



cout<< word << st.word<< endl;

cout<< wd << wd<< endl;

}
int main()



Repro a;
a.View();

返回0;

}
I wrote a program way back when VC++ 5.0 was around and when using
this program in VC++ 2003 I get garbage. I was able to let the
program run through code that would view the data. Since each object
is new there should be no data to show. Here is some code that would
run clean in VC++ 5.0 and in VC++ 2003 there is garbage.

//Reproduce Garbage

#include <iostream>

using std::cout;

using std::endl;

class Repro

{

private:

char wd[10];

struct

{

char word[10];

}st;

public:

void View();

};

void Repro::View()

{

cout << "word " << st.word << endl;

cout << "wd " << wd << endl;

}

int main()

{

Repro a;

a.View();

return 0;

}




你的程序都离开''wd ''和'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''这意味着它们包含垃圾。如果你想要

它们包含特定的东西,你必须具体说

so(在''Repro'的构造函数中)。如果你声明''a''*静态*,对于

实例,它占用的内存将被清零,并且'

有意义的东西。但就目前而言,''a''是*自动*并且它的

内存具有随机内容。


编译器之间的区别并不重要。 />

V

-

请在通过电子邮件回复时删除资金''A'

我没有回复最热门的回复,请不要问



Your program leaves both ''wd'' and ''st'' members of the ''a'' object
*uninitialised*. That means they contain garbage. If you want
them to contain something particular, you have to specifically say
so (in ''Repro''s constructor). If you declare ''a'' *static*, for
instance, the memory it occupies will be zeroed out, and that''s
something meaningful. But as it stands, ''a'' is *automatic* and its
memory has random contents.

The difference between compilers is immaterial.

V
--
Please remove capital ''A''s when replying by e-mail
I do not respond to top-posted replies, please don''t ask


在2006-05-26 19:32,Jeffrey Baker写道:
On 2006-05-26 19:32, Jeffrey Baker wrote:
你好,

当VC ++ 5.0出现时,我写了一个程序,当在VC ++ 2003中使用这个程序时,我得到了垃圾。我能够让程序通过可以查看数据的代码运行。由于每个对象都是新的,因此
应该没有数据显示。下面是一些在VC ++中运行干净的代码,在VC ++ 2003中有垃圾。
Hello,

I wrote a program way back when VC++ 5.0 was around and when using this
program in VC++ 2003 I get garbage. I was able to let the program run
through code that would view the data. Since each object is new there
should be no data to show. Here is some code that would run clean in VC++
5.0 and in VC++ 2003 there is garbage.




好​​像它正在按原样运行我。由于你还没有初步确定数据,因此当数据分配给内存时,无论是什么内存都是b
。使用VC ++ 5时你没有获得任何数据的原因是分配的内存被清零了,但它不是你的b $ b可以依赖。


Erik Wikstr?m

-

我一直希望我的电脑能像易于使用我的

电话;我的愿望实现了,因为我再也无法想象如何使用我的电话了。 - Bjarne Stroustrup



Seems like it''s working as it should to me. Since you have not
initialized the data it will be whatever was there when the memory was
allocated for the data. The reason that you didn''t get any data when
using VC++5 was that the memory allocated was zeroed out, but it''s not
something you can depend on.

Erik Wikstr?m
--
"I have always wished for my computer to be as easy to use as my
telephone; my wish has come true because I can no longer figure
out how to use my telephone" -- Bjarne Stroustrup


这篇关于VC ++ 5.0运行与VC ++ 2003不同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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