c++/388: Re: Bug report

Martin v. Loewis martin@loewis.home.cs.tu-berlin.de
Fri Jul 7 14:36:00 GMT 2000


>Number:         388
>Category:       c++
>Synopsis:       Bug report
>Confidential:   no
>Severity:       serious
>Priority:       low
>Responsible:    unassigned
>State:          analyzed
>Class:          ice-on-illegal-code
>Submitter-Id:   net
>Arrival-Date:   Fri Jul 07 14:36:00 PDT 2000
>Closed-Date:
>Last-Modified:
>Originator:     "John Nixon" <NixonJ@EM.AGR.CA>
>Release:        2.95.2
>Organization:
>Environment:
>Description:
 Original-Message-Id: <s9660731.068@EM.AGR.CA>
 Date: Fri, 07 Jul 2000 16:35:53 -0400

 This is a MIME message. If you are reading this text, you may want to 
 consider changing to a mail reader or gateway that understands how to 
 properly handle MIME multipart messages.

 --=_69313B61.10711D6B
 Content-Type: text/plain; charset=US-ASCII
 Content-Transfer-Encoding: quoted-printable
 Content-Disposition: inline

 [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
>How-To-Repeat:
#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:
  void 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=&(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;
}
>Fix:
>Release-Note:
>Audit-Trail:
>Unformatted:


More information about the Gcc-prs mailing list