ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Hi can u plz explain me what inline function means in c ?
Whats the difference with extern?
Can u provide me some examples when to use the one or the other?
Hmm, I assume inline functions are the same in C as they are in C++. When you inline a function, wherever that function is called, the code is copied there as if you had written it yourself. For example:
Code:
int Double(int x)
{
return 2*x;
}
int main()
{
int x = 2;
int y = Double(x);
return 0;
}
If you had declared Double() to be inline, the compiler would change your main() method to look like:
Code:
int x = 2;
y = 2 * x;
Generally, you only declare functions as inline if they contain a small number of statements (1 or 2, possibly a few more).
Inline code is also important in functions that will get called quite frequently. You can get quite an advantage by avoiding the function calls (pushing flags, pointers on stack, creating new stack, jumping, reversing the procedure, etc.)
This is common in loops where the same function may be called in multiple ways... it avoids functions calls, but allows you to update the same code all in once place.
hi
there is nothing like you should not use extern for function, just traverse linux source code, u will find extern declartion of function at so many places.
The keyword 'extern' is mandatory when referring to variables (as a variable definition and a variable declaration are the same) but optional when referring to functions. Generally, extern is used for a function from another file, the extern keyword is left off if the function is in the same file.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.