This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Bug report
- To: gcc-bugs at gcc dot gnu dot org
- Subject: Bug report
- From: "John Nixon" <NixonJ at EM dot AGR dot CA>
- Date: Fri, 07 Jul 2000 16:35:53 -0400
[john@otis programs]$ g++ -c test.c
test.c: In method `int matrix<T>::matdim(int, int)':
test.c:37: Internal compiler error.
test.c:37: Please submit a full bug report to `egcs-bugs@egcs.cygnus.com'.
test.c:37: See <URL:http://egcs.cygnus.com/faq.html#bugreport> for details.
I was in the process of trying to develop C++ code to implement a 2-dimensional array class that allows
dynamic allocation of arrays of arbitrary size, allows the array to be passed to a function using a pointer
while using automatic declaration and destruction of array objects (I had some trouble using dynamic allocation
which may be hard to sort out) .The principle of indexing the array using double indirection is explained
in ( Numerical recipies in C by William H Press et al. Cambridge University press page 20).
I am using a computer with Red Hat Linux release 6.0 (Hedwig).
My code attached caused the compiler to generate the message above, hence this email. If you are aware of a way to solve this problem please let me know.
Thanks
John Nixon
#include <stddef.h>
#include <string>
#include <string.h>
#include <ctype.h>
#include <time.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <iostream>
#include <cstdlib>
#include <math.h>
#include <algorithm>
#include <fstream>
#include <list>
/* compile with
g++ -c test.c
link with
g++ -o prog test.o
*/
template<class T>
class matrix{
int nrows,ncols;
T **x;
T (*y)[200];
T z[200][200];
public:
matdim(int i,int j){
cout.setf(ios::unitbuf);//allows output to be obtained even if program crashes.
int k;
nrows=i;ncols=j;
cout<<"nrows and ncols set\n";
x=(T **)&(y[0]);
cout<<"x initialized\n";
y[0]=(T *[200]) (&(z[0][0]) );
cout<<"y[0] initialized\n";
for(int k=1;k<nrows;k++){*y[k]=*y[k-1]+ncols*sizeof(T);}
cout<<"y[k] initialized\n";}
T &val(int i,int j){
if(i>=0 && i< nrows){
if(j>=0 && j <ncols){return z[i][j];}
else {cout<<"column (second) index "<<j<<" out of range\n";exit(1);}}
else {cout<<"row (first) index "<<i<<" out of range\n";exit(1);}}
};
int main(){
matrix<double> a;
cout<<"Matrix declared\n";
a.matdim(2,2);
cout<<"matrix dimensioned\n";
int k,l;
for(k=0;k<2;k++){for(l=0;l<2;l++)a.val(k,l)=k+l+1;};
cout <<"matrix defined\n";
for(k=0;k<2;k++){for(l=0;l<2;l++)cout<<a.val(k,l)<<" ";cout<<'\n';}
return 0;
}