In my project there's a C module which contains a small function. It is used twice in the module. I noticed that the program gets about 30 bytes smaller when I put the function into an external C module. Appearently the function is inlined in the first case which makes the program larger. This all was tested with -Os.
I guess this is not the only place where this happens. Is there a way to tell the compiler not to inline a function, except by putting it into another source file? (Don't laugh about this question, I'll run out of memory soon ;) )
Thomas
Less inline please...
-
- Experienced Member
- Posts: 94
- Joined: Tue Apr 27, 2010 10:55 pm
-
- Respected Member
- Posts: 318
- Joined: Tue Dec 15, 2009 12:46 am
You can use the noinline attribute in C to specify a function shouldn't be inlined. For example:
Code: Select all
static void f() __attribute__((noinline));
int x;
static void f()
{
x = 1;
}
void g()
{
/* This call won't be inlined. */
f();
}
-
- Experienced Member
- Posts: 94
- Joined: Tue Apr 27, 2010 10:55 pm
Great, thank you!