Link error.
/tmp/ccqpP1D1.o: In function `main':
tst.c:(.text+0x15): undefined reference to `foo'
collect2: ld returned 1 exit status
As Joseph said, I found the original text in c99 standard in section 6.7.4.
"
EXAMPLE The declaration of an inline function with external linkage can result
in either an external
definition, or a definition available for use only within the translation unit.
A file scope declaration with
extern creates an external definition. The following example shows an entire
translation unit.
inline double fahr(double t)
{
return (9.0 * t) / 5.0 + 32.0;
}
inline double cels(double t)
{
return (5.0 * (t - 32.0)) / 9.0;
}
extern double fahr(double); // creates an external definition
double convert(int is_fahr, double temp)
{
/* A translator may perform inline substitutions */
return is_fahr ? cels(temp) : fahr(temp);
}
8 Note that the definition of fahr is an external definition because fahr is
also declared with extern, but
the definition of cels is an inline definition. Because cels has external
linkage and is referenced, an
external definition has to appear in another translation unit (see 6.9); the
inline definition and the external
definition are distinct and either may be used for the call. "
I understand now the GCC implementation conforms to c99, but don't see
rationale behind it :-). Anyway,
this is not gcc dev question any more.
Cheers,
Bingfeng
> -----Original Message-----
> From: Richard Guenther [mailto:[email protected]]
> Sent: 31 March 2009 15:32
> To: Bingfeng Mei
> Cc: [email protected]
> Subject: Re: gcc99 inlining rules
>
> On Tue, Mar 31, 2009 at 4:24 PM, Bingfeng Mei
> <[email protected]> wrote:
> > Hello,
> > I found the following code doesn't compile with gcc4.4. and
> -std=c99. Does this behaviour conform to standard?
> >
> > inline int foo(){
> > return 10;
> > }
> >
> > int main(int argc, char **argv){
> > return foo();
> > }
>
> It works for me. What is your error?
>
> Richard.
>
>