473,666 Members | 2,258 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1910
>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*****@NOwrit emeNO.com> skrev i meddelandet
news:57******** *************** ***********@mic rosoft.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\...\qu ick_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\...\qu ick_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\...\qu ick_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
6117
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 file as folows. I need help to resolve them ASAP: cl /c /nologo /MDd /W3 /Od /GR /GM /Zi /GX /D "_DEBUG" /D " WIN32" /D "_W INDOWS" /D "_WINDLL" /D "_AFXDLL" /D "_MBCS" /D "_USRDLL" /
7
1557
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 CReplayBase::ReplayFillBuffer() { CFile* pFile = NULL;
5
2048
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 some investigating, I narrowed this down to a very odd behavior (bug?) of the VC++.NET 2003 compiler: If a class that is declared as __declspec(dllimport) derives from a template, that template's methods are never inlined, even if declared with...
22
3275
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 load DLL (aspnet_isapi.dll)." Of course the dll is able to be found, it's still in the framework directory and for grins I even put it in my service's local directory. This is apparantly server 2003 not allowing asp.net to be run if IIS was not...
0
8356
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
8550
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8639
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7385
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5663
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4198
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2769
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2011
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1772
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.