This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
g++ error report
- To: egcs-bugs at cygnus dot com
- Subject: g++ error report
- From: Yi <lyi at khasi dot mines dot edu>
- Date: Mon, 4 Jan 1999 11:48:50 -0500 (EST)
Hi,
I got the following message when I using g++ to compile a c++ progrom
which I used a friend function for a template class.
ProtoClu.cpp:29: Internal compiler error 9.
ProtoClu.cpp:29: Please submit a full bug report to
`egcs-bugs@cygnus.com'.
The souce code is attached. The information of the OS and g++&gcc are :
Linux khasi.mines.edu 2.0.35 #1 Fri Sep 11 04:06:03 EDT 1998 i686 unknown
-rwxr-xr-x 2 root root 61964 May 7 1998 g++*
-rwxr-xr-x 2 root root 44724 May 7 1998 gcc*
Thanks.
______________________________________________
Liyu Yi
Mathematical and Computer Sciences Department
Colorado School of Mines
Phone : (303) 273-3865
Homepage : http://www.mines.edu/students/l/lyi
// protoclu.cpp
#include <iostream.h>
#include <fstream.h>
#include <iomanip.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <math.h>
#include <time.h>
#include <ctype.h>
#include <assert.h>
#include "Parameter.h"
#include "Parameter.cpp"
// constants
const int OBJ_NAME_LEN = 16;
class OBJECT {
public:
int ObjIdx;
char ObjName[OBJ_NAME_LEN];
OBJECT * Next;
};
template <class dist_type>
class CLUSTER { //
friend void AssignObj2Clu <dist_type> (CLUSTER<dist_type> *Clusters, int CluNum);
public:
CLUSTER() {}; // empty constructor
~CLUSTER() {}; // empty destructor
void SetClu(OBJECT * ProtoObj) {Index = ProtoObj->ObjIdx;};
static void SetObj(OBJECT* objSet, int objNum, dist_type ** distMat) {ObjSet = objSet; ObjNum = objNum; DistMat = distMat;};
protected:
static OBJECT * ObjSet; // object set
static int ObjNum; // object number
static dist_type ** DistMat; // distance matrix
int Index; // index for the prototype object
OBJECT * CluMem; // cluster members
void PushMem(OBJECT * ObjIdx);
OBJECT * PopMem();
};
template <class dist_type>
OBJECT * CLUSTER<dist_type> :: ObjSet = NULL;
template <class dist_type>
int CLUSTER<dist_type> :: ObjNum = 0;
template <class dist_type>
dist_type ** CLUSTER<dist_type> :: DistMat = NULL;
// global variables
PARAMETER const *Param = NULL;
// Function Prototypes
void ProtoClu(ifstream &inFile, ifstream &lstFile, ofstream &outFile, int CluNum);
void Init(OBJECT *ObjSet, int **DistMat, CLUSTER<int> *Clusters,
ifstream& inFile, ifstream& lstFile, int ObjNum, int CluNum);
int main(int argc, char ** argv)
{
Param = new PARAMETER (argc, argv);
char inFileName[OBJ_NAME_LEN], lstFileName[OBJ_NAME_LEN], outFileName[OBJ_NAME_LEN];
ifstream inFile, lstFile;
ofstream outFile;
int CluNum; // cluster number
int pPos;
pPos = Param->findParam("-h"); // help
if (pPos != -1) {
cout << "Usage : ProtoClu [-h] [-if input_file] [-of output_file] [-cn cluter_number] " << endl;
return 0;
}
pPos = Param->findParam("-if");
if (pPos != -1)
strncpy(inFileName, Param->getParam(pPos+1), OBJ_NAME_LEN);
else {
cout << "Input file name : ";
cin >> inFileName;
}
pPos = Param->findParam("-lf");
if (pPos != -1)
strncpy(lstFileName, Param->getParam(pPos+1), OBJ_NAME_LEN);
else {
cout << "List file name : ";
cin >> lstFileName;
}
pPos = Param->findParam("-of");
if (pPos != -1)
strncpy(outFileName, Param->getParam(pPos+1), OBJ_NAME_LEN);
else {
cout << "Output file name : ";
cin >> outFileName;
}
pPos = Param->findParam("-cn");
if (pPos != -1)
CluNum = atoi(Param->getParam(pPos+1));
else {
cout << "Cluster number : ";
cin >> CluNum;
}
assert (CluNum > 0);
outFile.open(outFileName, ios::out);
if (!outFile) {
cout << "Can not open output file." << endl;
return -1;
}
inFile.open(inFileName, ios::in);
if (!inFile) {
cout << "Can not open input file." << endl;
return -1;
}
lstFile.open(lstFileName, ios::in);
if (!lstFile) {
cout << "Can not open list file." << endl;
return -1;
}
ProtoClu(inFile, lstFile, outFile, CluNum);
lstFile.close();
inFile.close();
outFile.close();
return 0;
}
void ProtoClu(ifstream &inFile, ifstream &lstFile, ofstream &outFile, int CluNum)
{
OBJECT * ObjSet; // objects
int ObjNum;
int ** DistMat; // distance matrix
int i, tmp;
lstFile >> ObjNum;
inFile >> tmp;
assert (ObjNum == tmp && ObjNum >= CluNum);
// allocate mem for objects and distance matrix
ObjSet = new OBJECT[ObjNum];
assert (ObjSet);
DistMat = new int* [ObjNum];
assert (DistMat);
for ( i=0; i<ObjNum; i++) {
DistMat[i] = new int[ObjNum];
assert (DistMat[i]);
}
CLUSTER<int> :: SetObj(ObjSet, ObjNum, DistMat);
// allocate mem for clusters
CLUSTER<int> * Clusters = new CLUSTER<int> [CluNum];
Init(ObjSet, DistMat, Clusters, inFile, lstFile, ObjNum, CluNum);
// free mem for clusters
delete [] Clusters;
// free mem for objects and distance matrix
delete [] ObjSet;
for ( i=0; i<ObjNum; i++)
delete [] DistMat[i];
delete [] DistMat;
return;
}
void Init(OBJECT *ObjSet, int **DistMat, CLUSTER<int> *Clusters,
ifstream& inFile, ifstream& lstFile, int ObjNum, int CluNum)
{
int i, j;
// read objects
for (i=0; i<ObjNum; i++) {
ObjSet[i].ObjIdx = i;
lstFile >> ObjSet[i].ObjName;
ObjSet[i].Next = NULL;
}
// read distance matrix
for (i=0; i<ObjNum; i++)
for (j=0; j<ObjNum; j++)
inFile >> DistMat[i][j];
// randomly initialize the prototypes
srand(time(0));
int *select = new int[ObjNum];
assert (select);
memset(select, 0, ObjNum);
for (i=0; i<CluNum; i++) {
int sel = rand()/ObjNum;
if (select[sel] == 0)
select[sel]++;
else
i--;
}
for (i=0, j=0; i<ObjNum; i++) {
if (select[i])
Clusters[j++].SetClu(&ObjSet[i]);
}
assert(j==CluNum);
delete [] select;
return;
}
template <class dist_type>
void AssignObj2Clu(CLUSTER<dist_type> *Clusters, int CluNum)
{
}