inline function

I try to use next declaration of inline function:

1
2
3
4
5
6
7
8
9
10
11
12
13
#include <stdio.h>
int main ()
{
    ...
    test();
    ....
    return 0;
}

inline void test(void)
{
    puts("Hello!");
}


And compiler shows me next error:
expected =, , , ; , asm or __attribute__ before void

What is wrong?
Already got it.
I checked out mode: "In C mode, support all ISO C90 programs."

The inline function declaration needs to appear before it's used. Mode, whatever that is, has nothing to do with it.
1
2
3
4
5
6
7
8
9
10
11
12
#include <stdio.h>

inline void test(void)
{
    puts("Hello!");
}

int main ()
{
    test();
    return 0;
}
btw, should we use the inline keyword? what's that used for compared if we don't use it? (for me, it is the same)
It basically tells the compiler that instead of calling a function (which could involve putting variables onto the stack, allocating memory, stuff that takes extra time), it could try to just insert the code directly at the call site, like this:

1
2
3
4
5
6
7
8
9
10
11
12
#include <stdio.h>

inline void test(void)
{
    puts("Hello!");
}

int main ()
{
    test();
    return 0;
}


becomes

1
2
3
4
5
6
7
#include <stdio.h>

int main ()
{
    puts("Hello!");
    return 0;
}
i just wanna get it straight so i don't have misunderstanding, when you call a function within main() the calling got stacked in the memory, like the value that passed by value or so forth, rather of calling it inlinedly which is faster... am i right?
Pretty much.
Topic archived. No new replies allowed.