|
-
March 17th, 2009, 01:07 AM
#1
Tricky Issue Involving Pointers and Segfaults
Hello,
I have the following very bizarre problem. I have written some code I have to integrate with a larger part of C++ programming. This program has some sketchy segfault issues. In particular, the program has to declare an array:
randomField = new double [N];
If however I add the line
double * randomfield;
before this line, then i get segfaults at some point in the program. The program is quite big and segfaults can be hard to track down (I'm planning to use a debugger), but can people here perhaps point me in the right direction from experience? My best guess is that when you just make the matrix using new, randomField is still a pointer but its a constant pointer. When you add the pointer declaration its not a constant pointer. I'm not sure how that could affects things. Help?
PS it also may be relevant to note that the program generates segfaults in certain other situations, most notably its supposed to output data to files and if that output is not disabled then I can get segfaults as well. I'm still tracking that down separately though.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|