Welcome to Dream.In.Code
Become a C++ Expert!

Join 149,987 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,385 people online right now. Registration is fast and FREE... Join Now!




How to 'inline' functions in C++ running Linux

 
Reply to this topicStart new topic

How to 'inline' functions in C++ running Linux, Moving a program from Windows to Linux/Unix

babasmith
18 Nov, 2006 - 03:45 AM
Post #1

New D.I.C Head
*

Joined: 2 Apr, 2006
Posts: 34


My Contributions
Hi,

I wrote a program in Windows (compiling with GNU) and now I'm trying to make it work in Linux. The only thing that I couldnt make work are the 'inline' functions.

If I remove the 'inline' directive from the functions signatures (in the .h and .cpp files) it works well.

What I'm trying to do is to avoid jumps in the code run for a few funcs that are used very often, since the running time is much important in this case than the size of the executable.


Thanks,
Baba.
User is offlineProfile CardPM
+Quote Post

gregoryH
RE: How To 'inline' Functions In C++ Running Linux
18 Nov, 2006 - 04:39 AM
Post #2

D.I.C Regular
Group Icon

Joined: 4 Oct, 2006
Posts: 417


Dream Kudos: 50
My Contributions
QUOTE(babasmith @ 18 Nov, 2006 - 04:45 AM) *

Hi,

I wrote a program in Windows (compiling with GNU) and now I'm trying to make it work in Linux. The only thing that I couldnt make work are the 'inline' functions.

If I remove the 'inline' directive from the functions signatures (in the .h and .cpp files) it works well.

What I'm trying to do is to avoid jumps in the code run for a few funcs that are used very often, since the running time is much important in this case than the size of the executable.


Thanks,
Baba.

Hi

What version of the compiler are you using? It may not support the inline under linux (though its now part of the standard)
User is offlineProfile CardPM
+Quote Post

Xing
RE: How To 'inline' Functions In C++ Running Linux
18 Nov, 2006 - 04:41 AM
Post #3

D.I.C Addict
Group Icon

Joined: 22 Jul, 2006
Posts: 723



Thanked: 4 times
Dream Kudos: 1575
My Contributions
Inline is simply a request to compiler. You cannot force compiler to inline your code. You have to be very cautious while using inline keyword.
User is offlineProfile CardPM
+Quote Post

babasmith
RE: How To 'inline' Functions In C++ Running Linux
1 Dec, 2006 - 05:27 AM
Post #4

New D.I.C Head
*

Joined: 2 Apr, 2006
Posts: 34


My Contributions

I'm using Mandrake 10.1 as the Linux, and for Windows I compile with GNU.

In Windows, I just mention 'inline' and thats it but the Linux doesnt recognize it. Someone once told me that for the function that I want to inline, in Linux/Unix I just have to write it (the whole function body) in the header (.h) file, and its meaning would be as the 'inline' for the Windows.

Do you have any idea whether it is true or not? I tried to figure it out but no clear conclusion.

Thanks
User is offlineProfile CardPM
+Quote Post

Trogdor
RE: How To 'inline' Functions In C++ Running Linux
1 Dec, 2006 - 05:36 AM
Post #5

D.I.C Addict
Group Icon

Joined: 6 Oct, 2006
Posts: 549



Thanked: 4 times
Dream Kudos: 125
My Contributions
Are you sure the trouble is worth it ?
Inline functions often have unexpected side-effects, and, imho, are best avoided completely.

User is offlineProfile CardPM
+Quote Post

babasmith
RE: How To 'inline' Functions In C++ Running Linux
1 Dec, 2006 - 06:06 AM
Post #6

New D.I.C Head
*

Joined: 2 Apr, 2006
Posts: 34


My Contributions

If it works then it worth it. I'm about to finish a project for a bioinformatic purpose where the run
time of the app is very important. I can trade-off the size of the executable for running-time.

After searching the web again I'm pretty sure that I've to put the implementation code for the func I want to inline inside the .h file, is it correct? And if so, then do I still have to mention the word 'inline' in the .h file?

Now I've a conceptual question: if I inline an objects method, not static, will it work? Cause the 'inline' thing happens in compilation-time, and objects are dynamic. Anyway, if I 'inline' a method that uses the object's variables/members, then still it would consume time for getting those members right?

Thanks
User is offlineProfile CardPM
+Quote Post

gregoryH
RE: How To 'inline' Functions In C++ Running Linux
1 Dec, 2006 - 03:40 PM
Post #7

D.I.C Regular
Group Icon

Joined: 4 Oct, 2006
Posts: 417


Dream Kudos: 50
My Contributions
QUOTE(babasmith @ 1 Dec, 2006 - 07:06 AM) *

If it works then it worth it. I'm about to finish a project for a bioinformatic purpose where the run
time of the app is very important. I can trade-off the size of the executable for running-time.

After searching the web again I'm pretty sure that I've to put the implementation code for the func I want to inline inside the .h file, is it correct? And if so, then do I still have to mention the word 'inline' in the .h file?

Now I've a conceptual question: if I inline an objects method, not static, will it work? Cause the 'inline' thing happens in compilation-time, and objects are dynamic. Anyway, if I 'inline' a method that uses the object's variables/members, then still it would consume time for getting those members right?

Thanks

Baba

The short answer is Yes, you can inline object code. The modern compilers check that the code will be available (because the object should be made available) and tries to inline (as Xing pointed out) where possible.

Have you checked the compiler options? These may have an impact on the compilation process.

Trogdor,

Every feature of the compiler will give some positive and negative attributes to the outcomes. It is the responsibility of the programmer to ensure his code is tested near its anticipated boundaries and range checking is used to prevent side effects.
User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 1/8/09 07:41PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month