🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.c++.help
Article #2

Re: Problems with inline key word

#2
From: Kevin Ingalls
Date: Wed, 11 Oct 1995 21:52
51 lines
2175 bytes
huili@dec2.mc.duke.edu (Huili Wang) wrote:
>Here is a simple program to demonstrate the problem with the inline
>key word that I encountered.
>
>#include <iostream.h>
>
>inline float square(float);
>
>main()
>{
> float y, x = 3.0;
>
> y = square(x);
> cout << y << "\n";
>}
>
>inline float square(float x)
>{
> return(x * x);
>}
>
>I put this program with main() and square(float x) functions in
>one file and compiled the program using g++.  Everything is ok.
>Then I put main() in one file try1.c and square(float x) function
>in the second file try2.c.  I compiled try2.c first using the command
>  g++ -c try2.c
>to get try2.o and compiled try1.c using the command
>  g++ try1.c try2.o -o try1
>I got the following messages:
>
>Warning: 'float square(float)' declared 'static' but never defined
>/bin/ld
>Unresolved:
>square(float)
>
>Does anyone know what was wrong?  
>
>Huili

I am no g++ expert, but answering this question from a C++ standpoint 
it seems to me that you are attempting to defeat the purpose of 
the "inline" keyword. The purpose of "inline", as you know, is to
avoid the overhead of a function call when invoking a function. This
is simular to the effect of a function macro in C. Therefore, the 
definition of the function must be around *at compile time*. You 
cannot link in the defintion of an inline function, it is too late
by then, as the object module is already built.

Hope this helps.

Kevin Ingalls, (206)773-9404, ingkl900@ccmail.ca.boeing.com
Technical Details
Message-ID: <DGB0r5.83E@bcstec.ca.boeing.com>
Path: arc1-ca.pugleaf.net!in2.uu.net!bcstec!nntp
References: <45h1mh$in8@news.duke.edu>

Show Full Headers
Complete Article Headers
Newsgroups: gnu.c++.help,comp.lang.c++
Path: arc1-ca.pugleaf.net!in2.uu.net!bcstec!nntp
From: Kevin Ingalls <ingkl900@ccmail.ca.boeing.com>
Subject: Re: Problems with inline key word
X-Nntp-Posting-Host: 137.136.17.87
Content-Type: text/plain; charset=us-ascii
Message-ID: <DGB0r5.83E@bcstec.ca.boeing.com>
To: huili@dec2.mc.duke.edu
Sender: nntp@bcstec.ca.boeing.com (NNTP News Access)
Content-Transfer-Encoding: 7bit
Organization: Boeing Defense & Space Group Training
References: <45h1mh$in8@news.duke.edu>
Mime-Version: 1.0
Date: Wed, 11 Oct 1995 21:52:16 GMT
X-Mailer: Mozilla 1.1N (Macintosh; I; PPC)
X-Url: news:45h1mh$in8@news.duke.edu