[comp.std.c++] 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

timh@.mentorg.com (Tim Harvey @ APD x1381) (01/19/91)

Eric Valette (Article 496) thought that AT&T C++ 2.0 might be efficacious.
I don't think so in this case.

I ran C++/cfront version 2.0 release 2c on his example, and as you can
see below, the C output looks fine.

Eric, did you take your question to where ever you got your cfront port?
It looks like you posted gnu.g++.help.  Are you using gnu g++?


//  C++ source code
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() ;
}




Compiled on an Apollo 4500.  Generated C code follows.
C++/cfront version 2.0 release 2c [apollo.mc68000.sys5.]
"t.c", line 13: warning:  loc used but not set


char  *__vec_new() ;
char  __vec_delete() ;

typedef int  (*__vptp)() ;

struct __mptr {
    short  d ;
    short  i ;
    __vptp f ;
};

struct example {
    int a__7example ;
};

extern struct __mptr *__ptbl_vec__t_c_[] ;

static int getVal__7exampleFv( __0this )
struct example *__0this ;
{
  return __0this->a__7example ;
}

static char setVal__7exampleFi( __0this, __0val )
struct example *__0this ;
int __0val ;
{
  __0this->a__7example = __0val ;
}

struct example glob = { 0 } ;

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

  setVal__7exampleFi( &__1loc, 1 ) ;
  __1resu = getVal__7exampleFv( &__1loc ) ;

  setVal__7exampleFi( &glob, 1 ) ;
  __1resu = getVal__7exampleFv( &glob ) ;
}