[net.lang.c++] Question about 'inline' functions

rudell@cad.UUCP (Richard Rudell) (03/10/86)

Consider the following c++ program:


	#include <stream.h>
	#include <complex.h>

	main()
	{
	    complex a = complex(1.0, 1.0);
	    complex b = complex(1.0, 1.0);
	    complex c = complex(1.0, 1.0);
	    complex d = complex(1.0, 1.0);

	    complex e = (a + b) + (c + d);

	    cout << e << "\n";
	}


The '+' overload for type complex is:

	friend	complex	operator+(complex, complex);
			.
			.
			.
	inline complex operator+(complex a1, complex a2) 
	{
		return complex(a1.re+a2.re, a1.im+a2.im);
	}

By examining the output of cfront for the above program, I find that only
1 of the three '+' operators is actually expanded inline.  A dummy
function is created which performs the addition operation, and then this
function is called twice to handle the final two additions.

My questions are: 
    Why isn't the entire expression placed "inline" ?
and: 
    Is this a temporary limitation, or a necessary (and hence
    permanent) limitation of c++ ?

Thanks in advance,
Richard Rudell
UC Berkeley
... ucbvax!cad!rudell