What is inline?

What is inline?

Post by Ivo » Mon, 16 Sep 2002 15:24:24



Sorry guys, I am a seasonal programmer and my question may seem stupid
but what is "inline". I've seen it many times, I even used but have no
idea why - I was thinking it has something to do with performance.

Thanks Ivo

 
 
 

What is inline?

Post by Eric P. McC » Mon, 16 Sep 2002 15:32:41



> Sorry guys, I am a seasonal programmer and my question may seem stupid
> but what is "inline". I've seen it many times, I even used but have no
> idea why - I was thinking it has something to do with performance.

It does.  It's a hint to the compiler that it should consider
inserting the inline function where it's used, rather than simply
calling it (which is what it would do normally).  I think it was
originally a C++ thing to replace macro-functions, but then people
turned out to like it and so it's part of C now.

So anyway, if you have this function:

  inline int my_function(int x) {
    return x + 3;
  }

And you call it like this:

  int main(void) {
    return my_function(7);
  }

That would be pretty equivalent to:

  int main(void) {
    return ((7) + 3);
  }

One important difference is that compilers will usually ignore the
inline request when you have optimizations off, which is logical
enough when you think about it.  There are also some funky tricks in C
you can do with this, like "overriding" functions with inlines, but
only in a particular source file.  Generally you'll want to stay away
from that, but it's still kind of cool.

--

"Last I checked, it wasn't the power cord for the Clue Generator that
was sticking up your ass." - John Novak, rasfwrj

 
 
 

What is inline?

Post by Ivo » Tue, 17 Sep 2002 23:29:07


Thanks Eric,

Now I see there is to it there that I do not understand, is there any
good book on this topic. So far I have read books, explaining
language syntax and technics but I've never encounter any book
discussing inner workings of that "magic".
I am really interested in learning more about it.

Ivo

 
 
 

1. "extern inline" to "static inline" allows compile

Hi,

I can't compile 2.5.51 on an EV56 without this. Tested, boots.
There are a bunch of symbols in core_cia.h that break the build if they're
extern inline because they're only defined in the header now. Make them
static inline instead. (Important, since they're #defined to things like
inb)

Comments?

Matt

diff -Nru a/include/asm-alpha/core_cia.h b/include/asm-alpha/core_cia.h
--- a/include/asm-alpha/core_cia.h      Thu Dec 12 16:59:06 2002

 #ifdef __KERNEL__

 #ifndef __EXTERN_INLINE
-#define __EXTERN_INLINE extern inline
+#define __EXTERN_INLINE static inline
 #define __IO_EXTERN_INLINE
 #endif

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in

More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

2. A couple of tin questions

3. static inline, and extern inline in the kernel source

4. QUES: Using dpsnx.agent

5. why is "static inline" preferred over "extern inline"?

6. task scheduling mklinux

7. This clone thing...am I stupid, or am I right?

8. HELP with DHCP on Solaris 8

9. I am with the following error, when i am running lilo...

10. Am I touchy? Or am I right?

11. Am I seeing IPv5, or am I hallucinating?

12. I am buying an Ultra 5 but am lost in part numbers ....