[gnu.g++.help] AT&T C++ 2.0 efficacious?

ev@chorus.fr (Eric Valette) (01/14/91)

/*
 *	The following small c++ program has been translated to c using
 *	one Cfront 2.0 port. If you look at generated c code, you will
 * 	see that the code generated for inlines member functions is different
 *	for local variables and global variables (it is also true for global
 *	pointer)
 *
 *	Could someone explain me why ?
 *	
 *	PS: I think that the code is ineffective. Tell me if I am wrong.
 *	
 */

/*
 *
 *	Sorry to post it in these news group, I have already post it in 
 *	comp.lang.c++ and got no answer.
 */


/*	Small C++ program
 * --------------------------------------------------------------------------
 *
 */

class example {
private :
	int a;
public :
	int getVal() {return a;}
	void setVal(int val) {a = val;}
};

example glob;

void f() 
{
	example loc;
	int a = 1;
	int b = 2;
	int resu;
	
	loc.setVal(1);
	resu = loc.getVal();

	glob.setVal(1);

	resu = glob.getVal();
}

/*
 * Generated C code
 * -------------------------------------------------------------------------
 * 
 */

/* <<AT&T C++ Translator 2.00.02 08/25/89>> */
/* < kt34.cxx > */

char	*__vec_new ();

char	__vec_delete ();
typedef int	(*__vptp)();
struct __mptr {
	short	d; 
	short	i; 
	__vptp f; 
};

struct example {	/* sizeof example == 4 */

	int	a__7example ;
};

struct example glob = { 
	0 };

char	f__Fv ()
{
	struct example __1loc ;
	int	__1a ;
	int	__1b ;
	int	__1resu ;

	struct example *__0__Xthis00a3jpkk ;

	struct example *__0__Xthis0020bpkk ;

	__1a = 1 ;
	__1b = 2 ;

	( ((&__1loc )->a__7example = 1 ), (((char )0 ))) ;
	__1resu = ( (&__1loc )->a__7example ) ;

/*
 * for local variables the c code is what I expected.
 */
 

	( (__0__Xthis00a3jpkk = (&glob )), ( (__0__Xthis00a3jpkk ->a__7example = 1 ), (((char )0 ))) ) ;
	__1resu = ( (__0__Xthis0020bpkk = (&glob )), ( __0__Xthis0020bpkk ->a__7example ) ) ;
/*
 * Why two copies? Why into two differents local variables?
 */
}







--
   __                 
  /  `                   	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