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();
}

I goolged the c99 inlining rule as follows. They does't seem to say such code 
cannot be compiled. 
 
C99 inline rules

The specification for "inline" is section 6.7.4 of the C99 standard (ISO/IEC 
9899:1999). This isn't freely available, but you can buy a PDF of it from ISO 
relatively cheaply.

    *

      A function where all the declarations (including the definition) mention 
"inline" and never "extern". There must be a definition in the same translation 
unit. No stand-alone object code is emitted. You can (must?) have a separate 
(not inline) definition in another translation unit, and the compiler might 
choose either that or the inline definition.

      Such functions may not contain modifiable static variables, and may not 
refer to static variables or functions elsewhere in the source file where they 
are declared.
    *

      A function where at least one declaration mentions "inline", but where 
some declaration doesn't mention "inline" or does mention "extern". There must 
be a definition in the same translation unit. Stand-alone object code is 
emitted (just like a normal function) and can be called from other translation 
units in your program.

      The same constraint about statics above applies here, too.
    * A function defined "static inline". A local definition may be emitted if 
required. You can have multiple definitions in your program, in different 
translation units, and it will still work. This is the same as the GNU C rules.


Cheers,
Bingfeng Mei

Reply via email to