🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.g++.bug
Article #148

(none)

#148
From: Garbett
Date: Mon, 03 Aug 1992 06:45
74 lines
1910 bytes
This is a bug in g++ 2.2.2 (at least I think it is) that exists on a decstation
and a next. The code core dumps with a segmenation fault on the recursive
call. This did not exist under g++ 1.39. 

This was compiled with the simple line:
  g++ test_list.cc

The workaround we are using is to make the function in question a 
friend function instead of a member function.

%%%% This is the file list.h 

#include <iostream.h>

class list
{
	private:
		int	num;
		list	*next;
	public:
		// Constructors
		inline list() { next = NULL; num = 0; }
		inline list(int the_num) { next = NULL; num = the_num; }
		inline list(list *next_node) { next = next_node; num = 0; }
		list(int the_num, list *next_node)
			{ next = next_node, num = the_num; }

		// Normal Usage
		inline void	display_value() { cout << num; }
		inline list *get_next()		 { return next; }

		// Recursive function and culprit of core dump
		void print_all() ;
};

%%%%%% This is the file test_list.cc

#include "list.h"

void list::print_all()
{
	cout << num << "\n";

	if( next != NULL)
		next->print_all();
}

int main()
{
	int	i;
	list	*top, *curr;

	for(i=0, top = NULL; i<10; i++)
		top = new list(i, top); 

	curr = top;

	/* This works */
	do
	{
		curr->display_value();
		cout << "\n";
		curr = curr->get_next();
	} while (curr != NULL);

	cout << "\n" << "Testing Recursive Function\n";

	/* Get ready for a segmenatation fault */
	curr->print_all();
}

%%% End of files

Garbett@utkvx.utk.edu
Technical Details
Message-ID: <9208031445.AA05419@utknp3.phys.utk.edu>
Path: arc1-ca.pugleaf.net!sparky!uunet!cis.ohio-state.edu!utknp3.phys.utk.edu!garbett

Show Full Headers
Complete Article Headers
Newsgroups: gnu.g++.bug
Path: arc1-ca.pugleaf.net!sparky!uunet!cis.ohio-state.edu!utknp3.phys.utk.edu!garbett
From: garbett@utknp3.phys.utk.edu (Garbett)
Subject: (none)
Message-ID: <9208031445.AA05419@utknp3.phys.utk.edu>
Sender: gnulists@ai.mit.edu
Organization: GNUs Not Usenet
Distribution: gnu
Date: Mon, 3 Aug 1992 06:45:08 GMT
Approved: bug-g++@prep.ai.mit.edu
Lines: 75