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: Wesley Eddy <weddy at p1 dot cs dot ohiou dot edu>
- Date: Wed, 10 May 2000 22:16:22 -0400 (EDT)
gcc version 2.95.2 19991024
on SunOS 5.6
options are in Makefile which is attached with the code
output said:
Internal compiler error 980605
Have fun!
// Wesley M. Eddy
// 5/6/00
//
// List template class
#include<stdlib.h>
#include<iostream.h>
template <class Type>
struct Node {
Type data;
Node<Type> *next;
};
template <class Type>
class List {
public:
List();
~List();
void add(Type& addme);
void remove(Type rmme);
void display();
private:
Node<Type> *head,
*tail;
int length;
};
template <class Type>
List<Type>::List() {
head = tail = NULL;
length = 0;
}
template <class Type>
List<Type>::~List() {
while (head != NULL)
remove(head->data);
}
template <class Type>
void List<Type>::add(Type& addme) {
if (head == NULL) { // list was empty
// debug code
cout << "adding to beginning" << endl;
//
head = new Node<Type>;
head->next = NULL;
head->data = addme;
tail = head;
length++;
return;
}
else {
// debug code
cout << "adding to end" << endl;
//
tail->next = new Node<Type>; // else tack it on at the end
tail = tail->next;
tail->next = NULL;
tail->data = addme;
length++;
return;
}
}
template <class Type>
void List<Type>::remove(Type rmme) {
Node<Type> *cursor = head;
if (head == NULL)
return;
else if (head->data == rmme) { // if it was first
Node<Type> *temp = head->next, *oldhead = head;
delete head;
head = temp;
if (tail == oldhead) // for case where only one item was on list
tail = head;
}
else while (cursor != tail) { // otherwise go looking
if (cursor->next->data == rmme) {
Node<Type> *temp = cursor->next->next;
if (cursor->next == tail) tail = cursor;
delete cursor->next;
cursor->next = temp;
length--;
return;
}
}
}
template <class Type>
void List<Type>::display() {
Node<Type> *cursor = head;
while (cursor != NULL) {
cout << cursor->data;
cursor = cursor->next;
}
}
#This file was provided by Dr. David Juedes
#This is a generic makefile for CS240B
#Copy this file to your program directory.
#Give it the name "Makefile"
#Then, if you issue the command "make",
#This command will compile all of your .C files using g++, and
#it will link the resulting object code. It then deletes all
#object files.
#
# Type "make clean" to remove all object files from your
# directory.
#
CC = g++
CFLAGS = -g
PROGS:sh = ls *.cc;
OBJECTS = ${PROGS:%.cc=%.o}
all: $(OBJECTS)
$(CC) $(CFLAGS) $(OBJECTS); rm *.o
%.o:%.cc
$(CC) $(CFLAGS) -c $*.cc
clean:
rm *.o
#include"symbol.h"
ostream &operator <<(ostream& outs, Variable outme) {
outs << outme.VarType << " " << outme.VarName
<< " " << outme.VarVal << endl;
return outs;
}
bool operator ==(Variable& var1, Variable& var2) {
bool ret = true;
if (var1.VarType != var2.VarType || var1.VarName != var2.VarName ||
var1.VarVal != var2.VarVal) {
ret = false;
}
return ret;
}
SymbolTable::SymbolTable() {
}
SymbolTable::~SymbolTable() {
for (size_t i = 0; i < SIZE; i++) {
*variables[i].~List();
delete variables[i];
}
}
void SymbolTable::add(Variable& addme) {
*variables[hash(addme.VarName)].add(addme);
}
void SymbolTable::remove(Variable& rmme) {
}
void SymbolTable::display() {
for (size_t i = 0; i < SIZE; i++)
variables[i]->display();
}
size_t SymbolTable::hash(string hashme) {
size_t ret = 0;
for (int i = 0; i < hashme.length(); i++) {
ret += hashme.at(i);
}
// debug code
cout << ret << endl;
//
return (ret % SIZE);
}
Variable find(string findme) {
}
// Wesley M. Eddy
// 5/7/99
//
// Header file for symbol table class - chained hash table
#include<string>
#include"List.h"
#define SIZE 103
struct Variable {
string VarType,
VarName,
VarVal;
};
class SymbolTable {
public:
SymbolTable();
~SymbolTable();
void add(Variable& addme);
void remove(Variable& rmme);
void display();
size_t hash(string hashme);
Variable find(string findme);
private:
List<Variable> (*variables)[SIZE];
};
#include"symbol.h"
int main() {
List<char> chars;
char a = 'a', b = 'b';
chars.add(a);
chars.add(b);
chars.display();
cout << endl;
SymbolTable symbols;
Variable v;
cout << "got this far without core dump!" << endl;
v.VarName = "myname";
v.VarType = "int";
v.VarVal = "junk";
symbols.add(v);
symbols.display();
return EXIT_SUCCESS;
}