| Author |
New - initialization
|
Lazaro Caruso
Greenhorn
Joined: Jan 03, 2011
Posts: 12
|
|
Hi,
I thought that when I use new "with round brackets", it zeroes matrix, but today I found something strange. Here is the code:
And here is my output:
0: 6956096
1: 6955792
2: 0
3: 0
4: 0
5: 0
6: 0
7: 0
8: 0
9: 0
Why t[0] and t[1] aren't zeros? I am using Code Blocks 8.02
|
 |
Anthony Aj Williams
author
Ranch Hand
Joined: Jun 10, 2011
Posts: 56
|
|
Lazaro Caruso wrote:
I thought that when I use new "with round brackets", it zeroes matrix,
That is supposed to be the case. An initializer of () should value-initialize the array, which value-initializes each element. For int objects, value-initialization means initialization with zero.
Lazaro Caruso wrote:Hi,Why t[0] and t[1] aren't zeros? I am using Code Blocks 8.02
I guess there's a bug in the compiler. I have known other compilers have bugs with regards to value-initialization of int objects.
|
Author of C++ Concurrency in Action http://www.stdthread.co.uk/book/
just::thread C++11 thread library http://www.stdthread.co.uk
Just Software Solutions Ltd http://www.justsoftwaresolutions.co.uk
15 Carrallack Mews, St Just, Cornwall, TR19 7UL, UK. Company No. 5478976
|
 |
Lazaro Caruso
Greenhorn
Joined: Jan 03, 2011
Posts: 12
|
|
|
Mhm so it's all about compiler. Thanks for reply.
|
 |
Anand Hariharan
Rancher
Joined: Aug 22, 2006
Posts: 252
|
|
Lazaro Caruso wrote:Mhm so it's all about compiler.
Code Blocks is an IDE that can be configured to use any compiler. Which compiler are you using?
Why don't you use a vector?
|
"Perfection is achieved, not when there is nothing more to add, but when there is nothing left to take away." -- Antoine de Saint-Exupery
|
 |
 |
|
|
subject: New - initialization
|
|
|