🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: net.lang.c++
Article #81

Question about 'inline' functions

#81
From: Richard Rudell
Date: Mon, 10 Mar 1986 05:19
46 lines
1597 bytes
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
Technical Details
Message-ID: <94@cad.UUCP>
Path: arc1-ca.pugleaf.net!utzoo!watmath!clyde!burl!ulysses!ucbvax!cad!rudell

Show Full Headers
Complete Article Headers
Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Posting-Version: version B 2.10.3 4.3bsd-beta 6/6/85; site cad.UUCP
Path: arc1-ca.pugleaf.net!utzoo!watmath!clyde!burl!ulysses!ucbvax!cad!rudell
From: rudell@cad.UUCP (Richard Rudell)
Newsgroups: net.lang.c++
Subject: Question about 'inline' functions
Message-ID: <94@cad.UUCP>
Date: Mon, 10-Mar-86 00:19:07 EST
Article-I.D.: cad.94
Posted: Mon Mar 10 00:19:07 1986
Date-Received: Tue, 11-Mar-86 01:21:47 EST
Organization: U. C. Berkeley CAD Group
Lines: 46
Keywords: inline