473,396 Members | 1,833 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

VS.2003, __inline and __forceinline

Hello,
I'm having strange issues with inline functions in VS.2003.
In following simple code snippet:

extern
int mytmp1( int v ) { return !v; };

extern int mytmp( void )
{
return mytmp1( -7 );
}

I see mytmp1 expanded inline, despite option /Ob1 (expand only __inline) iin
the project.
Is this normal? Does this depend on C or C++ mode or debug/release mode?

Another question about __inline extensions in pure C mode (MS specific, not
c++):
Are the following statements valid? All they compile clean, but I doubt
whether this can cause "undefined behavour" or is 100% legal:

A. __inline int foo1(...) { ... }

B. int __inline foo2( ... ) { ... }

C. __inline int foo3( ...); // proto
int foo3(...) {... } // separate body

D. static __inline int foo3( ...); // proto
extern int foo3(...) {... } // __inline with static or extern ??

Could somebody explain please?

Best regards,
Pavel
--
Nov 17 '05 #1
4 1900
>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.


Pavel,

Do you have a small console application that illustrates the issue?

Dave
Nov 17 '05 #2
"David Lowndes" wrote:
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.


Pavel,

Do you have a small console application that illustrates the issue?

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

Nov 17 '05 #3

"Pavel A." <pa*****@NOwritemeNO.com> skrev i meddelandet
news:57**********************************@microsof t.com...
"David Lowndes" wrote:
>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.
Pavel,

Do you have a small console application that illustrates the issue?

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


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
Nov 17 '05 #4
>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
--
MVP VC++ FAQ: http://www.mvps.org/vcfaq
Nov 17 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Tom Lee | last post by:
Hi, I'm new to .NET 2003 compiler. When I tried to compile my program using DEBUG mode, I got the following errors in the C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7 \include\xdebug...
7
by: Michael Kennedy [UB] | last post by:
Hi, I am back with more bug reports from Visual Studio.NET 2003's C++ compiler (unmanaged). Consider the following method: --------------------------------------------- __forceinline bool...
5
by: Felix I. Wyss | last post by:
Good Afternoon, I recently noticed that some very simple methods of a template declared and used in a DLL library get inlined when used by the DLL itself, but not by other DLLs and EXEs. After...
22
by: EP | last post by:
When running my asp.net hosting service (asp.net without IIS), on server 2003 with IIS not installed, I get the following when trying to process a request. "System.DllNotFoundException: Unable to...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.