Jump to content

Inline Functions

- - - - -

  • Please log in to reply
9 replies to this topic

#1
roboticforest

roboticforest

    Programmer

  • Members
  • PipPipPipPip
  • 110 posts
Is there a way to make a non-inline function inline for a single call?
Dave

#2
dargueta

dargueta

    Writes binary right handed and hex left handed

  • Moderators
  • 4,717 posts
  • Programming Language:C, Java, C++, PHP, Python, Perl, Assembly, Bash, Others
  • Learning:JavaScript
Stupid cheap way:
inline void __inline_blah()
{
    ...stuff...
}

void blah()
{
    __inline_blah();
}

Just call __inline_blah() that one time. I think that'll work, but don't quote me on it.
sudo rm -rf /

#3
Ancient Dragon

Ancient Dragon

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 400 posts
>>Is there a way to make a non-inline function inline for a single call?

No -- it's either inline or it isn't. Note that __inline is only a hint to the compiler -- the compiler is free to ignore it if it wishes.
Visit Grandpa's Forums, a social networking forum, with family-oriented arcade games, blogs, discussion forums, and photo albums.

#4
dargueta

dargueta

    Writes binary right handed and hex left handed

  • Moderators
  • 4,717 posts
  • Programming Language:C, Java, C++, PHP, Python, Perl, Assembly, Bash, Others
  • Learning:JavaScript
Microsoft compilers will actually refuse to compile if your program contains the keyword.
sudo rm -rf /

#5
roboticforest

roboticforest

    Programmer

  • Members
  • PipPipPipPip
  • 110 posts
Thanks. :-)
Dave

#6
Ancient Dragon

Ancient Dragon

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 400 posts

dargueta said:

Microsoft compilers will actually refuse to compile if your program contains the keyword.

I never had a problem with them -- I have been using M$ compilers since about 1990. You must have done something else that was not legal.
Visit Grandpa's Forums, a social networking forum, with family-oriented arcade games, blogs, discussion forums, and photo albums.

#7
dargueta

dargueta

    Writes binary right handed and hex left handed

  • Moderators
  • 4,717 posts
  • Programming Language:C, Java, C++, PHP, Python, Perl, Assembly, Bash, Others
  • Learning:JavaScript
A number of years ago, when I was using Visual Studio 2005 (or something along those lines) I tried using those keywords for the first time, and VS barfed on me. It specifically complained that it was deliberately ignoring register and inline. I distinctly remember being pissed.

Whether this is still the case, I don't know. I'll test it on my VM (too lazy to reboot) and see.
sudo rm -rf /

#8
zoranh

zoranh

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 207 posts
I think that MS compilers are still (silently) ignoring register and inline directives. That is somehow correct, because optimizers have become so good these days that your decision to make something inline or to force some variable to be kept in register looks provisional compared to elaborate analyses performed by the optimizer.

When deciding what will be inline and what will be stored in register, compiler and optimizer must take into account many things, including CPU architecture, observed memory speed, etc. For example, knowing that CPU pipeline is flushed on every falsely predicted branch instruction (because subsequent instructions executions have been started by mistake), then optimizes tend to reorganize code so that pipeline flush has least possible impact.

Now, imagine that you enforce inline and/or register directives - how can you be sure that it will not put optimizer into situation to be unable to increase efficiency of compiled code because of unnatural constraints? As a result of all this, optimizers operate differently on different CPU architectures, when given the same C++ code on input.

On an unrelated note - Microsoft code since many years ago is generally compiled with "optimize for size" switch on.

#9
Ancient Dragon

Ancient Dragon

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 400 posts
Saying Microsoft compilers ignore inline keyword is a lot different than saying the compilers refuse to compile the code.

register Keyword (C++)

Quote

Microsoft Specific

The compiler does not accept user requests for register variables; instead, it makes its own register choices when global register-allocation optimization (/Oe option) is on. However, all other semantics associated with the register keyword are honored.

The inline keyword is somewhat different -- it may or may not be honored, depending on the program
inline, __inline, __forceinline
Visit Grandpa's Forums, a social networking forum, with family-oriented arcade games, blogs, discussion forums, and photo albums.

#10
dargueta

dargueta

    Writes binary right handed and hex left handed

  • Moderators
  • 4,717 posts
  • Programming Language:C, Java, C++, PHP, Python, Perl, Assembly, Bash, Others
  • Learning:JavaScript
Seriously, I distinctly remember the compiler crapping out on me, and as soon as I removed inline or register it worked just fine. Maybe it was because I was using a trial version? I really don't know.
sudo rm -rf /




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users