>I'm having strange issues with inline functions in VS.2003.
>In following simple code snippet:
>...
>I see mytmp1 expanded inline, despite option /Ob1 (expand only __inline) iin
>the project.
> >I'm having strange issues with inline functions in VS.2003.
> >In following simple code snippet:
[quoted text clipped - 7 lines]
>
> Dave
Thanks David.
I've tried to get a "minimal" example, and found that the compiler
does very aggressive optimization.
It inlines and removes unused code everywhere.
By itself it is not bad. But why it ignores project options?
This is one variant, where everything gets inlined though
in project settings global optimization is off and inline only explicit.
--------
int /*__inline*/ aaa1( int v )
{ return !v; };
extern int tmp99( void )
{
printf("test1\n");
return aaa1( - 7 ) ;
}
int main(int argc, char* argv[])
{
tmp99();
return 0;
}
-------------
My specific question is, why VC syntax in C mode allows
extern __inline and even extern __forceinline ?
Doesn't __inline mean that the function is not visible outside
and can not be extern?
OTOH, if compiler decides to inline a function defined as extern, how
it knows that no another module calls it from outside?
I'm not sure how to post my sample. There is also .vcproj
and other files besides of .c
Regards,
Pavel
Bo Persson - 25 Jun 2005 17:03 GMT
>> >I'm having strange issues with inline functions in VS.2003.
>> >In following simple code snippet:
[quoted text clipped - 33 lines]
> return 0;
> }
Here is the result I get with your example. Inline /Ob1, global
optimization on
--- c:\documents and settings\...\quick_test.cpp
#include "stdio.h"
int /*__inline*/ aaa1( int v )
{ return !v; };
00401000 xor eax,eax
00401002 cmp dword ptr [esp+4],eax
00401006 sete al
00401009 ret
--- c:\documents and settings\...\quick_test.cpp
extern int tmp99( void )
{
printf("test1\n");
00401010 push offset string "test1\n" (406D4Ch)
00401015 call printf (401038h)
return aaa1( - 7 ) ;
0040101A push 0FFFFFFF9h
0040101C call aaa1 (401000h)
00401021 add esp,8
}
00401024 ret
--- c:\documents and settings\...\quick_test.cpp
int main(int , char* [])
{
tmp99();
00401030 call tmp99 (401010h)
return 0;
00401035 xor eax,eax
}
00401037 ret
Seems to work very well as intended.
> -------------
>
> My specific question is, why VC syntax in C mode allows
> extern __inline and even extern __forceinline ?
> Doesn't __inline mean that the function is not visible outside
> and can not be extern?
But 'extern' means that it is. :-)
> OTOH, if compiler decides to inline a function defined as extern, how
> it knows that no another module calls it from outside?
The linker knows. If you delay code generation until link time, the
system knows almost everything about the code.
Bo Persson
David Lowndes - 25 Jun 2005 23:16 GMT
>This is one variant, where everything gets inlined though
>in project settings global optimization is off and inline only explicit.
In your release build project settings, change the optimization
setting to custom rather than the default /O2 or /O1 options. I think
that other optimizations are having an effect.
Dave

Signature
MVP VC++ FAQ: http://www.mvps.org/vcfaq