🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

/usr/tmp/cc008448.s: 18530:FATAL:Symbol ___pl already defined. (gcc 2.3.1)

#53
From: Ernest Prabhakar
Date: Tue, 03 Nov 1992 07:04
213 lines
5149 bytes
I've gotten this error a number of times.

/usr/tmp/cc008448.s:18530:FATAL:Symbol ___pl already defined.
*** Exit 1

I've gotten the smallest possible file that contains the problem included  
below.  In this particular case, I can eliminate the error by substituting a  
member function for the template inline function.  However, I still get this  
same error (under apparently similar circumstances) later on, even with the  
workaround here, so I need to get a real fix before I can do anything else.

I am using NeXTSTEP 3.0 (m68040, 25 MHz) with GCC 2.3.1 and libg++2.2  
(recompiled with 2.3.1)
Reading specs from /usr/local/lib/gcc-lib/next/2.3.1/specs
gcc version 2.3.1

I compile this routine with 'gcc Test.cc -o Test'
Thank you,

- Ernie P.
----------
Test.cc
-----------
extern "C" {
#include <string.h>
#include <stddef.h>
}

class BaseObject { };

typedef void *dataPtr;
class DAlist : public BaseObject
{
    /* Data members */
  protected:

    dataPtr* data;			/*array of references to data items*/
    size_t numElements;
    size_t maxElements;

  public:
    /****Status (non-virtual) functions****/
    

    size_t count(void) const { return numElements; }

    size_t capacity(void) const { return maxElements; }

    const dataPtr *pointer() const { return data; }

  protected:    

    /* Protected virtual (?) functions */
    

    void zero(int count, size_t offset)
    {
	/* negative shifts do nothing*/
	/* memset seemed to cause problems */
	for (int i=0; i < count; ++i)
	    data[offset+i]=NULL;
    }

    void setSize(size_t count)
    {
	maxElements = count;
	data = new dataPtr[count];
	/*Throw Exception if it runs out of memory!?*/
	zero(count,0);
    }

    void resize(size_t count)
    {
	dataPtr *oldData = data;
	setSize(count);
	memmove(data, oldData, numElements*sizeof(dataPtr));
	delete [] oldData;
    }

    virtual size_t growBy(size_t step=0) /*Double by default*/
    {
	size_t newSize = maxElements;
	newSize += (step>maxElements) ? step : maxElements;
	resize(newSize);
	return maxElements;
    }
    

    virtual size_t checkCapacity(int margin = 1)
    {
	if (margin <= 0) return 0;
	if (margin+numElements > capacity())
	    return growBy(margin);
	return 0;
    }
    

    virtual long shift(size_t index, long by)
    {
	int nToShift = numElements - index;
	
	checkCapacity(by);
	if (nToShift) 

	{
	    memmove(data+index+by, data+index, nToShift*sizeof(dataPtr));
	}
	zero(by,index);
	return numElements += by;
    }

  public:

    /* Constructors - from most arguments to the least */
    DAlist(size_t count=1)
    {
	numElements = 0;
	setSize(count);
    }
    

    /**Destructors**/
    virtual ~DAlist(void)
    {
	delete [] data;
    }

    int checkIndex(int &index) const
    {
	if ( (index>count()) || (index<0) )
	{
	    index = count();
	    return 0;
	}
	return 1;
    }
    

    /*** element manipulation ***/
    

    virtual DAlist& add(const dataPtr element, int index=-1)
    {
	if (!element) return *this; /* Don't add null pointers! */
	checkIndex(index); /* makes in reasonable range */
	shift((unsigned) index,1);
	data[index] = element;
	return *this;
    }

}; /*DAlist*/

template <class ObjType>
class TypedList :  public DAlist 

{
    /* No Data members - inherits from superclass */

   public:

    /*** element manipulation ***/
    virtual TypedList<ObjType>& operator+=(ObjType& element)
    {
	add((dataPtr) &element);
	return *this;
    }

/*
If 'SAFE' not defined, crashes with 

 		/usr/tmp/cc009312.s:803:FATAL:Symbol ___pl already defined.
or sometimes with cc1plus fatal error 10.
*/

//#define SAFE 

#ifdef SAFE
    TypedList<ObjType> operator+(ObjType& element)
    { 

	*this += element;
	return *this;
    }
#endif
}; /*TypedList*/

template <class ObjType>
inline TypedList<ObjType> operator+ (ObjType& e1, ObjType& e2)
{
    TypedList<ObjType> elist(2);
    elist += e1;
    elist += e2;
    return elist;
}

#ifndef SAFE
template <class ObjType>
inline TypedList<ObjType> operator+(TypedList<ObjType>& el1, ObjType& e1)
{
    TypedList<ObjType> elist(el1);
    elist += e1;
    return elist;
}
#endif

class Named : public BaseObject { } n1, n2, n3;

main()
{
    /*Test Typed List */
    TypedList<Named> type11;
    n1 + n2 + n3; //won't crash if this line absent.
}
Technical Details
Message-ID: <9211032304.AA09395@pundit.cithep.caltech.edu>
Path: arc1-ca.pugleaf.net!sparky!uunet!charon.amdahl.com!pacbell.com!iggy.GW.Vitalink.COM!cs.widener.edu!umn.edu!spool.mu.edu!sdd.hp.com!zaphod.mps.ohio-state.edu!magnus.acs.ohio-state.edu!cis.ohio-state.edu!pundit.cithep.caltech.edu!ernest

Show Full Headers
Complete Article Headers
Newsgroups: gnu.g++.bug
Path: arc1-ca.pugleaf.net!sparky!uunet!charon.amdahl.com!pacbell.com!iggy.GW.Vitalink.COM!cs.widener.edu!umn.edu!spool.mu.edu!sdd.hp.com!zaphod.mps.ohio-state.edu!magnus.acs.ohio-state.edu!cis.ohio-state.edu!pundit.cithep.caltech.edu!ernest
From: ernest@pundit.cithep.caltech.edu (Ernest Prabhakar)
Subject: /usr/tmp/cc008448.s: 18530:FATAL:Symbol ___pl already defined. (gcc 2.3.1)
Message-ID: <9211032304.AA09395@pundit.cithep.caltech.edu>
Sender: gnulists@ai.mit.edu
Reply-To: ernest@cco.caltech.edu
Organization: GNUs Not Usenet
Distribution: gnu
Date: Tue, 3 Nov 1992 07:04:37 GMT
Approved: bug-g++@prep.ai.mit.edu
Lines: 214