Inline functions

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
HOS

Inline functions

Post by HOS »

Hi, i am in the process of converting my kernel code from one main file that includes everything to .c files that are compiled into separate .o files and then linked together. my question is this: i have several functions like outportb, enable_ints, etc... that i have been using as 'inline' because they are very simple functions. i dont believe that i can keep them as inline if they are in a separate .o file from whatever is calling them, so the question is do i just define these functions in the main kernel file so they can still be inline? will that even work for other .o files to call them then? or is it not worth it / feasible to even keep them as inline functions?

thanks
sup

Re:Inline functions

Post by sup »

write your code as c code but write these functions as inline c++ funtions and put em in .h files then use a c++ compiler as long as your not using any of the troublesome features of c++ this shouldn't be a problem and should give the funtionality that you want... but who knows I may just be speaking out of my @$$.
HOS

Re:Inline functions

Post by HOS »

ah - i think you have something there. i dont know why using c++ would be necessary, but stupid me i never even thought of putting the inline function itself in the .h file, then every "module" would have access to the inline function - i think this should work

thanks!
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re:Inline functions

Post by Solar »

C as devised by K&R doesn't have provisions for declaring a function "inline" - that was left to the compiler to decide. Later revisions of the C standard introduced that keyword, so you could use "gcc -std=c99" instead of "g++". (C++ had "inline" right from the start.)
Every good solution is obvious once you've found it.
Post Reply