Usenet comp.unix.osf.osf1 (1992-2004)
 help / color / mirror / Atom feed
From: buffat@europe.mecaflu.ec-lyon.fr (Buffat Marc)
Subject: DEC cxx BUGc
Date: 2 Sep 1994 17:26:22 GMT	[thread overview]
Message-ID: <347n7u$l7u@cismsun.univ-lyon1.fr> (raw)


I am using the C++ compiler of DEC cxx with OSF 2.0, 
           DEC C++ V1.3A-0 for DEC OSF/1 (Alpha)
and I try to declare and use
an array of class object (with no default constructor). I have some 
problem (i.e. a Segmentation fault) and I want to know if it is because
I am doing wrong or because of a compiler bug
Here is the example:

#include <stdio.h>
#include <iostream.h>
class A {
private:
  int N;
  float *tab;
public:
  A(int n):N(n) { tab=new float[N]; }
  ~A() { delete tab; }
  float & operator()(int i) { return tab[i]; } 
  friend ostream& operator<<(ostream &s,A &X);
};
ostream& operator<<(ostream &s,A &X)
{
  for (int i=0; i<X.N; i++) s<<X(i)<<" ";
  return s;
}
void main()
{
  int n=10;
  A X[3]={n,n,n}; 
  for(int i=0; i<n;i++) {
    X[0](i)=i; X[1](i)=2*i; X[2](i)=3*i;
  }
  cout<<"X="<<endl;
  cout<<X[0]<<endl;cout<<X[1]<<endl;cout<<X[2]<<endl;
  A Y[3]={n,n,n};
  for(i=0; i<n;i++) {
    Y[0](i)=4*i; Y[1](i)=5*i; Y[2](i)=6*i;
  }
  cout<<"X="<<endl;
  cout<<X[0]<<endl;cout<<X[1]<<endl;cout<<X[2]<<endl;
  cout<<"Y="<<endl;
  cout<<Y[0]<<endl;cout<<Y[1]<<endl;cout<<Y[2]<<endl;
}

then the result
a.out 
X=
0 1 2 3 4 5 6 7 8 9 
0 0 4 6 8 10 12 14 16 18 
0 0 0 0 12 15 18 21 24 27 
X=
0 1 2 3 4 5 6 7 8 9 
0 4 8 12 16 20 24 28 32 36 
0 5 10 15 20 25 30 35 40 45 
Y=
0 4 8 12 16 20 24 28 32 36 
0 5 10 15 20 25 30 35 40 45 
0 6 12 18 24 30 36 42 48 54 
Segmentation fault (core dumped)
which is wrong (X being modified)
Thanks for any advise
				Marc

PS: its a compiler BUG, because the program work on a SUN with cfront v2.0
-- 
-----------------------------------------------------------------------------
Marc BUFFAT                                 ++++++++++++++++++++++++
Lab. Mecanique des fluides LMFA             |     CNRS URA 263     |
ECL, 36 av. Guy de Collongue                |     ECL Lyon         |
Ecully 69131, FRANCE                        |     UCB Lyon I       |
tel: (33) 72/18/61/61                       ++++++++++++++++++++++++
fax: (33) 78/64/71/45                      
email: buffat@mecaflu.ec-lyon.fr



-- 
-----------------------------------------------------------------------------
Marc BUFFAT                                 ++++++++++++++++++++++++
Lab. Mecanique des fluides LMFA             |     CNRS URA 263     |
ECL, 36 av. Guy de Collongue                |     ECL Lyon         |
Ecully 69131, FRANCE                        |     UCB Lyon I       |
tel: (33) 72/18/61/61                       ++++++++++++++++++++++++
fax: (33) 78/64/71/45                      
email: buffat@mecaflu.ec-lyon.fr


             reply	other threads:[~1994-09-02 17:26 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1994-09-02 17:26 Buffat Marc [this message]
1994-09-09 19:41 ` DEC cxx BUGc Jeff Diewald
read-only archive

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox