Skip to main content
GameDev.net gamedev.net
🔒 Locked

Inlining

Started by dbzprogrammer Oct 30, 2005 at 3:54 PM 11 replies 900+ views
Original Post
dbzprogrammer
dbzprogrammer
Any function that has it's complete definition in the class is "automatically inlined." What about this? Would the compiler inline this? Example.h

class Example
{
private:
  int number;
public:
  Example(int num) : number(num)
  {   }  //This is automatically inlined

  inline int GetNumber();
};


Example.cpp

#include "Example.h"

inline int GetNumber()
{
  return number;
}


We should do this the Microsoft way: "WAHOOOO!!! IT COMPILES! SHIP IT!"
Sneftel
Sneftel
Functions marked inline need to be declared in the translation unit in which they are used. So no, the compiler won't inline that if the function is used in other source files. It won't even compile it.
mfawcett
mfawcett
Quote:
Original post by Sneftel
Functions marked inline need to be declared in the translation unit in which they are used. So no, the compiler won't inline that if the function is used in other source files. It won't even compile it.

Quite a few compilers perform inlining during the link stage as well, in which case, that function (and even functions you didn't ask to be inlined) may become inlined.
--Michael Fawcett
Sneftel
Sneftel
Quote:
Original post by mfawcett
Quite a few compilers perform inlining during the link stage as well, in which case, that function (and even functions you didn't ask to be inlined) may become inlined.

No, it won't be inlined, because it won't compile (if used in a different source file).
mfawcett
mfawcett
Quote:
Original post by Sneftel
Quote:
Original post by mfawcett
Quite a few compilers perform inlining during the link stage as well, in which case, that function (and even functions you didn't ask to be inlined) may become inlined.

No, it won't be inlined, because it won't compile (if used in a different source file).

I thought we were ignoring the obvious compilation errors and talking about the general case.
--Michael Fawcett
Sneftel
Sneftel
Ah, I see. Yes, that's a good point: LTCG means that the programmer generally no longer needs to think about function inlining. Especially given that the program's allowed to NOT inline a function even if you do all the inline rigamarole. In other words, inline is about on the same level as register.
mfawcett
mfawcett
Yes, sorry for the confusion.
--Michael Fawcett
dbzprogrammer
dbzprogrammer
Quote:
Original post by Sneftel
Quote:
Original post by mfawcett
Quite a few compilers perform inlining during the link stage as well, in which case, that function (and even functions you didn't ask to be inlined) may become inlined.

No, it won't be inlined, because it won't compile (if used in a different source file).


NOT true... Or I have a really funky compiler, because it's letting me do the double inline thing or whatever you want to call it. I'm using VC++ 6.0.
We should do this the Microsoft way: "WAHOOOO!!! IT COMPILES! SHIP IT!"
Boku San
Boku San
Quote:
Original post by dbzprogrammer
NOT true... Or I have a really funky compiler, because it's letting me do the double inline thing or whatever you want to call it. I'm using VC++ 6.0.


I'm using VC++ 6.0. I have a really funky compiler
Things change.
iMalc
iMalc
Quote:
Original post by Boku San
NOT true... Or I have a really funky compiler, because it's letting me do the double inline thing or whatever you want to call it. I'm using VC++ 6.0.
That's probably because the one that is in your cpp file isn't even a class member, i.e. it has no "Example::".

So although it may compile, it may not link because it's missing Example::Get Number().
Red Ant
Red Ant
Is explicitely inlining stuff even necessary these days? I've been told that compilers are smart enough to know when it's best to inline a function and when not to without needing to be told by the programmer.
Zahlman
Zahlman
Quote:
Original post by Red Ant
Is explicitely inlining stuff even necessary these days? I've been told that compilers are smart enough to know when it's best to inline a function and when not to without needing to be told by the programmer.


Not really, and pretty much:

Quote:
Original post by Sneftel
In other words, inline is about on the same level as register.


...Though perhaps not *quite* on the same level *yet* :) After all, people are still using things like VC++ 6.0 :)

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.