🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: Problems with inline key word

#1
From: David Vandevoorde
Date: Thu, 12 Oct 1995 00:12
46 lines
1923 bytes
>>>>> "HW" == Huili Wang <huili@dec2.mc.duke.edu> writes:
[...]
HW> #include <iostream.h>
HW> inline float square(float);
HW> main()
HW> {
HW>  float y, x = 3.0;
HW>  y = square(x);
HW>  cout << y << "\n";
HW> }
HW> inline float square(float x)
HW> {
HW>  return(x * x);
HW> }

HW> I put this program with main() and square(float x) functions in
HW> one file and compiled the program using g++.  Everything is ok.
HW> Then I put main() in one file try1.c and square(float x) function
HW> in the second file try2.c.  I compiled try2.c first using the command
HW>   g++ -c try2.c
HW> to get try2.o and compiled try1.c using the command
HW>   g++ try1.c try2.o -o try1
HW> I got the following messages:

HW> Warning: 'float square(float)' declared 'static' but never defined
HW> /bin/ld
HW> Unresolved:
HW> square(float)

HW> Does anyone know what was wrong?  

I think so. According to my copy of the DWP (7.1.1/4 [dcl.stc])

	"[...] For a non-member function, an inline specifier is
	 equivalent to a static specifier for linkage purposes (3.5)
	 unless the linkage declaration matches a previous declaration
	 of the function, in which case the function retains the 
	 linkage of the previous declaration."

Hence, in your case all your declarations specify static linkage (i.e., 
the name is not visible across translation units). One way of resolving
this is to also declare your function `extern'.

HW> Huili

	Daveed
Technical Details
Message-ID: <VANDEVOD.95Oct11201206@avs.cs.rpi.edu>
Path: arc1-ca.pugleaf.net!usenet.rpi.edu!vandevod
References: <45h1mh$in8@news.duke.edu>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!usenet.rpi.edu!vandevod
From: vandevod@cs.rpi.edu (David Vandevoorde)
Newsgroups: gnu.c++.help,comp.lang.c++
Subject: Re: Problems with inline key word
Date: 12 Oct 1995 00:12:06 GMT
Organization: RPI Computer Science
Distribution: world
Message-ID: <VANDEVOD.95Oct11201206@avs.cs.rpi.edu>
References: <45h1mh$in8@news.duke.edu>
NNTP-Posting-Host: avs.cs.rpi.edu
In-reply-to: huili@dec2.mc.duke.edu's message of 11 Oct 1995 18:16:49 GMT