Linux Format forums Forum Index Linux Format forums
Help, discussion, magazine feedback and more
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

C inline functions

 
Post new topic   Reply to topic    Linux Format forums Forum Index -> Programming
View previous topic :: View next topic  
Author Message
Crispy



Joined: Mon May 31, 2010 7:35 pm
Posts: 57

PostPosted: Thu Oct 03, 2013 12:56 pm    Post subject: C inline functions Reply with quote

Hi all,

I am hoping to use inline functions in a piece of C code that I have, but I am a bit confused about their proper use and was hoping someone would be able to help me. As an example, assume that I have a header file foo.h containing the prototype of the function int func_foo() and a source file foo.c containing the declaration of the function func_foo(), e.g.

foo.h
Code:

int func_foo( void );


foo.c
Code:

#include "foo.h"

int func_foo( void )
{
  ...
}


Then I have another file, bar.c, which includes foo.h so it can use the function func_foo(), e.g.

bar.c
Code:

#include "bar.h"
#include "foo.h"

int func_bar( void )
{
  ...
 
  x = func_foo();

  ...
}


Assuming that func_foo() is a good candidate for inlining, I am a bit confused as to the proper way to define the inline function func_foo. Should I place the inline keyword in the function prototype in the header file, foo.h, or in the function declaration in foo.c or both? Also, i've had a look around and some people suggest using the extern keyword in the header file as well as the inline keyword?

Also, if we assume that func_bar() is also suitable for inlining and is called often, is it better for me to inline both func_foo() and func_bar() or just func_bar or func_foo by themselves?

Finally, if we consider an additional file, foobar.c which contains the function func_foobar, e.g.

foobar.c
Code:

#include "foobar.h"

int func_foobar( int (*func)( void ) )
{
  ...

  x = (*func)();

  ...
}


And we assume that (*func) points to an inline function, will the inlining optimisation still hold within the function func_foobar? Or will it simply be treated as a normal function?

Many thanks in advance,

Chris
Back to top
View user's profile Send private message
View previous topic :: View next topic  
Display posts from previous:   
Post new topic   Reply to topic    Linux Format forums Forum Index -> Programming All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Linux Format forums topic RSS feed 


Powered by phpBB © 2001, 2005 phpBB Group


Copyright 2011 Future Publishing, all rights reserved.


Web hosting by UKFast