Bug 304441 - Console output of program running under CDT is not same as its output running directly
Summary: Console output of program running under CDT is not same as its output running...
Status: RESOLVED INVALID
Alias: None
Product: CDT
Classification: Tools
Component: cdt-debug (show other bugs)
Version: 6.0   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: cdt-debug-inbox@eclipse.org CLA
QA Contact: Ken Ryall CLA
URL:
Whiteboard:
Keywords: test
Depends on:
Blocks:
 
Reported: 2010-03-02 21:14 EST by catigger CLA
Modified: 2014-09-22 04:34 EDT (History)
4 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description catigger CLA 2010-03-02 21:14:38 EST
Hi
  I wrote a short program of the dynamic array,the result is not the expect.but I got it when i execute it directly in windows,the following is the part of the program:
int main()
{
	string *psa = new string[10]();//this array initialized
	int *pia = new int[10];  //this array not initialized
	bitset<32> bs(*pia);

	cout << "psa first element: " << *psa << endl;  //ok,the result is blank
	cout << "pia first element: " << *pia << endl;  //should be random digit in int scope
	cout << "pia bitset: " << bs << endl;           //should be all zeros

	const int *pci_ok = new const int[100](); //this array initialized
	cout << "const dynamic array: " << *pci_ok << endl; //should be 0
}

CDT console output is :
psa first element: 
pia first element: 3998328
pia bitset: 00000000001111010000001001111000
const dynamic array: 4017984

but the direct executing result is :
psa first element: 
pia first element: 0
pia bitset: 00000000000000000000000000000000
const dynamic array: 0
Comment 1 Elena Laskavaia CLA 2010-03-03 12:26:43 EST
I doubt cdt console changing output on you, which means this
is depends on launch environment, which probably means stuff you think
is initialized isn't.
Comment 2 Elena Laskavaia CLA 2010-03-03 12:36:05 EST
From my C++ knowledge there is no difference between x a[]; and x a[]();
Default constructor will be called in any case. In case of "int"
 - there is no constructor.
Comment 3 catigger CLA 2010-03-03 20:15:41 EST
(In reply to comment #2)
> From my C++ knowledge there is no difference between x a[]; and x a[]();
> Default constructor will be called in any case. In case of "int"
>  - there is no constructor.

I thought it was,they are primitive,and have no constructor.but i got that the x a[](); will be initialized with default "ZERO",x a[]; will not from <<C++ primer>>.
This is not the point, I just want to know about the reason of the difference between the CDT console(may be should be call eclipse console) output and the program direct output. 

I want to know how can I solved this problem, if caused by launch environment.

Thanks
Comment 4 Anton Leherbauer CLA 2010-03-04 03:40:06 EST
In C/C++ world, nothing is initialized by default.  If you don't write code to initialize your structures, they contain random bits.  This has nothing to do with CDT or Eclipse.
Comment 5 Elena Laskavaia CLA 2010-03-04 09:40:16 EST
You should not spent any time at difference between the environment, you
should initialize you variables - this is only reliable solution