🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.g++.help
Article #269

problem with operator new and g++1.37.1

#269
From: Eric Valette
Date: Wed, 24 Oct 1990 14:35
84 lines
2086 bytes
/*
 *
 *	The following program compiles when using Cfront 2.0.
 *	
 *	The syntax used in function f() to call the foo::new operator seems
 *	to be incorrect for g++1.37.1. (this syntax is described in 
 *	" the annotated C++ reference manual" by A. Ellis & B Stroustrup
 *	p 60.
 *	
 *	What is the correct syntax for g++1.37.1?
 *	
 *	NB : I can not use a global __user_new operator (I have exactly the
 *	same problem in many classes).
 *	
 *	I need an answer in order to compile the chorus kernel with g++ !!
 *	
 *	Thanks,
 *	
 */


extern "C" {

char * malloc(int size);
void free(void*);

}

// typedef unsigned long size_t; // for g++
typedef unsigned int size_t; 

class foo {
	char * ptrData;
	int x;
public:
	foo (int j);
	int get () {return x;}
	void* operator new (size_t , int stringSize);
	void* operator new (size_t) {return 0;}	// just to make Cfront 2.0 happy
						// (needed for global object)
	void  operator delete (void*);
};

	void*
foo::operator new (size_t fooSize, int stringSize) {
	
	return malloc(fooSize + stringSize);
}

	void
foo::operator delete (void* ptr) {
	
	free(ptr);
}

foo::foo (int j) {
	x =j;
	ptrData = ((char *) this + sizeof(foo));
}

int f()
{

	// with g++ I get a parse error on the following line :
	foo *ptr = new (100) foo(2);
	return ptr->get();
	
}

/*
 *
 *
   __                 
  /  `                   	Eric Valette
 /--   __  o _.          	Chorus Systemes
(___, / (_(_(__         	6 avenue Gustave Eiffel
				F-78182, St-Quentin-en-Yvelines-Cedex

Tel: +33 (1) 30 64 82 00	Fax: +33 (1) 30 57 00 66
E-mail: ev@chorus.fr		or ev%chorus.fr@mcsun.EU.net

 *
 *
 */
Technical Details
Message-ID: <6607@chorus.fr>
Path: arc1-ca.pugleaf.net!utzoo!telly!attcan!uunet!tut.cis.ohio-state.edu!chorus.fr!ev

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!telly!attcan!uunet!tut.cis.ohio-state.edu!chorus.fr!ev
From: ev@chorus.fr (Eric Valette)
Newsgroups: gnu.g++.help,comp.lang.c++
Subject: problem with operator new and g++1.37.1
Message-ID: <6607@chorus.fr>
Date: 24 Oct 90 14:35:17 GMT
Sender: daemon@tut.cis.ohio-state.edu
Followup-To: gnu.g++.help
Distribution: gnu
Organization: GNUs Not Usenet
Lines: 84