>My probelm occurs for large uneven matrices where I end up getting a segmentation fault.
By default, Visual C++ 6 doesn't throw an exception when new fails, it returns a null pointer just like malloc. Your problem looks suspiciously like one of the allocations is failing and then you try to dereference a null pointer. Your first order of business should be adding proper error handling code so that you can have a better idea of where the source of the problem is rather than the symptom.
Narue
Bad Cop
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401
>What is it exactly about: mat_Data[i][j] = 1 that could cause a seg.
A segmentation fault is caused when you access memory outside of your address space. Subscripting an array is effectively a pointer dereference, and if the indices are beyond the bounds of the array then you'll probably get a seg fault. If one of your allocations fails then you're working with a null pointer, which can't be dereferenced, which will crash and burn if you try, which is what appears to be happening.
>I've tested the program under different compilers
Different compilers may be new enough to throw an exception rather than return a null pointer.
>how could I better implement error-checking procedures in my program.
mat_Data = new int *[m_Rows];
if ( mat_Data == NULL ) {
// Error! There's not a whole lot you can do though, terminate gracefully
}
Repeat that process for every use of new and you'll have gone a long way toward improving your error handling.
Narue
Bad Cop
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401