aspose file tools*
The moose likes C / C++ and the fly likes New - initialization Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of JavaScript Promises Essentials this week in the JavaScript forum!
JavaRanch » Java Forums » Languages » C / C++
Bookmark "New - initialization" Watch "New - initialization" New topic
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: 57
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: 257

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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: New - initialization