LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices



Reply
 
Search this Thread
Old 03-14-2005, 09:03 AM   #1
markhod
Member
 
Registered: Sep 2003
Posts: 103

Rep: Reputation: 15
odd behaviour of array elements in c++


Hi,

I am using someones class and they define a data member:

double** m_patl;

and in the constructor they do:

m_patl = new double*[376000];

for (int i = 0; i < 376000; i++){
m_patl[i] = new double [5];
}


I had some problem with the code getting stuck in this class and eventually found some elements of this array are nans. And eventually I tracked down a part of the code where

m_patl[0][2]==170

then the code does: m_patl[7][2]=m_patl[0][2]

and a cout shows that m_patl[7][2] is nan instead of 170. (on the next line - no code is inbetween) Any ideas on how to debug this from here?

btw the original author is not contactable so I cant just ask them why their code doesnt work...

Cheers for any pointers (no pun intended),

Mark

Last edited by markhod; 03-14-2005 at 09:15 AM.
 
Old 03-14-2005, 09:15 AM   #2
Hivemind
Member
 
Registered: Sep 2004
Posts: 273

Rep: Reputation: 30
The above code allocates a two-dimensional array, a matrix if you will, of doubles. Like a vector<vector<double> >. And it's very big. Since it doesn't set the elements in the matrix to any values it's no wonder that some elements are NANs. I'm not sure what the problem is though because your post isn't very clear, but giving each element a value, say 0.0, is probably a good idea.
 
Old 03-14-2005, 09:16 AM   #3
markhod
Member
 
Registered: Sep 2003
Posts: 103

Original Poster
Rep: Reputation: 15
Yeah, I already tried that and the problem persists even if I initialise all the values...
 
Old 03-14-2005, 09:20 AM   #4
Hivemind
Member
 
Registered: Sep 2004
Posts: 273

Rep: Reputation: 30
Try to make a small, self-contained example exhibiting the problem, using no platform specific libraries if possible and I will have a look at it. But you will probably find the problem when doing this. Or change the code to use vectors instead.
 
Old 03-14-2005, 10:58 AM   #5
markhod
Member
 
Registered: Sep 2003
Posts: 103

Original Poster
Rep: Reputation: 15
I tried a small self-contained example. Unfortunately it works perfectrly well! I tried building it up to be more and more complex but the problem is not manifesting itself. So I am at a loss as to the problem at the moment. I guess I'll try vectors in the actual code and see if that makes a difference..

Thanks for triyng to help,

Mark
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Deleting elements from array in perl with splice signalno9 Programming 2 08-16-2005 11:57 PM
odd behaviour of wvdial NNP Linux - General 4 08-05-2005 03:58 PM
perl - get number of elements in an array AM1SHFURN1TURE Programming 3 03-07-2005 04:59 PM
Odd behaviour on desktop... user00265 Slackware 19 02-26-2005 07:06 PM
Odd Ogg behaviour Misel Linux - Software 3 05-04-2003 04:18 PM


All times are GMT -5. The time now is 11:17 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration