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 14 1771
Jeffrey Baker wrote: 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. 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 wrote: 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;
}
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
On 2006-05-26 19:32, Jeffrey Baker wrote: 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.
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
--
It is far better to post code then to never have posted
"mlimber" <ml*****@gmail.com> wrote in message
news:11**********************@y43g2000cwc.googlegr oups.com... Jeffrey Baker wrote: 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. 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
I only need to add a contructor like strcpy(st.word, " ") and everything is
cleaned.
jb
Jeffrey Baker wrote: -- It is far better to post code then to never have posted "mlimber" <ml*****@gmail.com> wrote in message news:11**********************@y43g2000cwc.googlegr oups.com... Jeffrey Baker wrote: 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. 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
I only need to add a contructor like strcpy(st.word, " ") and everything is cleaned.
jb
Well, first that's not "a constructor" at all (that term has a specific
meaning in C++ land). It's an initialization you could put in the
constructor body. But it would work, though you could improve upon it
in several ways, e.g., by using an empty string ("") or by doing
something something shorter like:
Repro::Repro()
{
wd[0] = 0;
st.word[0] = 0;
}
Or better still, don't use a raw array or the C-style string functions
at all. Use std::string (see http://www.parashift.com/c++-faq-lit...html#faq-34.1), and
then that class' constructor will initialize it for you automatically.
Cheers! --M
mlimber wrote: Jeffrey Baker wrote: [..]
I only need to add a contructor like strcpy(st.word, " ") and everything is cleaned.
jb Well, first that's not "a constructor" at all (that term has a specific meaning in C++ land). It's an initialization you could put in the constructor body. But it would work, though you could improve upon it in several ways, e.g., by using an empty string ("") or by doing something something shorter like:
Repro::Repro() { wd[0] = 0; st.word[0] = 0; }
Actually, a compliant compiler should also accept
Repro::Repro() : wd(), st() {}
for that. Not sure if VC++ 2003 is that good. Probably not.
Or better still, don't use a raw array or the C-style string functions at all. Use std::string (see http://www.parashift.com/c++-faq-lit...html#faq-34.1), and then that class' constructor will initialize it for you automatically.
A raw array is often faster. I would agree if the OP was using pointers
and allocating C strings himself, though...
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Victor Bazarov wrote: mlimber wrote: Repro::Repro() { wd[0] = 0; st.word[0] = 0; }
Actually, a compliant compiler should also accept
Repro::Repro() : wd(), st() {}
for that. Not sure if VC++ 2003 is that good. Probably not.
Good point. Or better still, don't use a raw array or the C-style string functions at all. Use std::string (see http://www.parashift.com/c++-faq-lit...html#faq-34.1), and then that class' constructor will initialize it for you automatically.
A raw array is often faster. I would agree if the OP was using pointers and allocating C strings himself, though...
True, but assembly is also often faster. As you well know, correctness
and maintainability should be primary concerns, while speed should be
secondary (cf. the old adage about making a fast program correct vs.
making a correct program fast).
Cheers! --M
mlimber wrote: [..] As you well know, correctness and maintainability should be primary concerns, while speed should be secondary (cf. the old adage about making a fast program correct vs. making a correct program fast).
Well, to know how to make a correct program fast one should be aware
of the differences between 'std::string' and how it manages its memory
and a plain array as a member, and what the implications are for using
one versus the other. That's why I am not convinced that the sweeping
generalisation that it's "better still" to use 'std::string' here.
Speaking from experience, mind you. So, I do "well know".
Victor Bazarov wrote: mlimber wrote: [..] As you well know, correctness and maintainability should be primary concerns, while speed should be secondary (cf. the old adage about making a fast program correct vs. making a correct program fast). Well, to know how to make a correct program fast one should be aware of the differences between 'std::string' and how it manages its memory and a plain array as a member, and what the implications are for using one versus the other.
Sure.
That's why I am not convinced that the sweeping generalisation that it's "better still" to use 'std::string' here.
I'm just saying that the first choice for such usage should be
generally and sweepingly be std::string. When the speed of std::string
is proven by measurement to be an issue, then other options should be
considered.
Cheers! --M
Victor Bazarov <v.********@comacast.net> wrote: mlimber wrote: Repro::Repro() { wd[0] = 0; st.word[0] = 0; }
Actually, a compliant compiler should also accept
Repro::Repro() : wd(), st() {}
for that. Not sure if VC++ 2003 is that good. Probably not.
It is not.
See: http://groups.google.com/group/comp....b44a8b786b6a79
and Dietmar Kuehl's followup. They have fixed it in VC+ 2005. However,
you can work around this in a standards-compliant manner by wrapping the
class in another: http://groups.google.com/group/micro...0dbefaa1c4286/
--
Marcus Kwok
Replace 'invalid' with 'net' to reply
Jeffrey Baker wrote:
Here's a technical note about your post. You properly posted your
comments after the quotes, but your newsreader slapped your .sig at the
very top. This put your entire post into your .sig. That's bad.
The reason this is happening it that you are using the braindead
Microsoft Outlook Express. There are few things you can do to correct
the problem:
1. Get a different newsreader. There are many good ones.
2. Don't use a .sig.
3. Find and install OE Quotefix.
Brian
"Default User" <de***********@yahoo.com> wrote in message
news:Iz*******@news.boeing.com... Jeffrey Baker wrote:
Here's a technical note about your post. You properly posted your comments after the quotes, but your newsreader slapped your .sig at the very top. This put your entire post into your .sig. That's bad.
The reason this is happening it that you are using the braindead Microsoft Outlook Express. There are few things you can do to correct the problem:
1. Get a different newsreader. There are many good ones.
2. Don't use a .sig.
3. Find and install OE Quotefix.
Brian
Funny.
--
It is far better to post code then to never have posted
"Victor Bazarov" <v.********@comAcast.net> wrote in message
news:e5**********@news.datemas.de... Jeffrey Baker wrote: 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;
}
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
Here is the program fixed -
//Reproduce Garbage lost due to Repro(){ strcpy(st.word," ");strcpy(wd,"
");}
#include <iostream>
using std::cout;
using std::endl;
#include <string>
class Repro
{
public:
Repro(){ strcpy(st.word," ");strcpy(wd," ");}
void View();
private:
char wd[10];
struct
{
char word[10];
}st;
};
void Repro::View()
{
cout << "word " << st.word << endl;
cout << "wd " << wd << endl;
}
int main()
{
Repro a;
a.View();
return 0;
}
I'll have to look at the "static" you mentioned.
Thanks,
Jeff
--
It is far better to post code then to never have posted
Jeffrey Baker wrote: "Default User" <de***********@yahoo.com> wrote in message news:Iz*******@news.boeing.com... Jeffrey Baker wrote:
Here's a technical note about your post. You properly posted your comments after the quotes, but your newsreader slapped your .sig at the very top. This put your entire post into your .sig. That's bad.
Funny.
??
I wasn't attempting to be funny. I was quite serious. OE Quotefix was
designed to repair that defect in Lookout Express. Do you not see the
signature at the top of the message?
Brian This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Boris Dynin |
last post by:
Hi,
I have some projects (native - not managed code) in VC++ 2003. I'm trying to
debug that stuff on Win98 system that has VC6.0 installed. Is it possible to
use VC6.0 for debugging code built...
|
by: zorro |
last post by:
Hi,
I use the Visual C++ .NET 2003 Standard Edition which doesn't include an
optimizing compiler. But Microsoft released the VC++ 2003 Toolkit
(http://msdn.microsoft.com/visualc/vctoolkit2003/)...
|
by: Michael |
last post by:
i experience slower compile times with VC++ 2003 compared to VC+6.0.
Anyone experiencing the same?
Should that be expected?
This ineed matters, when total compilation time is > 1h and you have to...
|
by: Harry Whitehouse |
last post by:
I'm porting an application from Borland C++ to VS .NET 2003. The VC++
compiler doesn't want to deal with declarations like this in my code:
LONG FAR PASCAL _export StdPVDlgProc(HWND hWnd, UINT...
|
by: Harry Whitehouse |
last post by:
I just wanted to confirm this for WIN32 projects in VC++ 2003.
It looks like you need to reference functions in 3rd party DLL's (C-based)
by building a LIB file as described here:
...
|
by: Felix I. Wyss |
last post by:
It appears that VC++2003 has a code generator bug related to template
parameters that are a pointer-to-member type:
If the actual template argument is a virtual method, VC generates code that...
|
by: Jason Doucette |
last post by:
I'm getting an assertion fire from a list iterator being checked
against NULL. This did not occur in VC++ 2003 (v7.1). Are there
changes that have been made to the STL between these versions that...
|
by: JohnIdol |
last post by:
VC++6 to VC++2003 - linking troubles
--------------------------------------------------------------------------------
Hi All,
I successfully ported an application from VC++6 to VS2003.
Solved...
|
by: pmbcan |
last post by:
I have a project written in VC++ 2003.NET which uses MFC classes.
I have ONLY VC++Express2005. I can open the VCProject file sucessfully. The
conversion takes place without any error. BUT the...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
| |