Results 1 to 10 of 13
It seems that inline functions are bound to the file it's defined in. Is there a possible way to overcome this?...
Enjoy an ad free experience by logging in. Not a member yet? Register.
- 05-13-2003 #1Linux Engineer
- Join Date
- Nov 2002
- Location
- Queens, NY
- Posts
- 1,319
inline functions
It seems that inline functions are bound to the file it's defined in. Is there a possible way to overcome this?
The best things in life are free.
- 05-14-2003 #2Linux Guru
- Join Date
- Oct 2001
- Location
- Täby, Sweden
- Posts
- 7,578
Where would you get such an idea. The difference is that inline functions defined in another file are not used inline in other files, for obvious reasons. In the kernel source code, they have overcome that by defining inline functions as static in the header files.
- 05-14-2003 #3Linux Engineer
- Join Date
- Nov 2002
- Location
- Queens, NY
- Posts
- 1,319
Well, I have two separate files. One is the file containing the main function with the appropriate function prototypes and the other is just the function definitions themself. When I compile these two, the compiler complains about the inline function.
The best things in life are free.
- 05-14-2003 #4Linux Guru
- Join Date
- Oct 2001
- Location
- Täby, Sweden
- Posts
- 7,578
Can you give an example? This worked perfectly for me:
File 1:
File 2:Code:#include <stdio.h> inline void test(int mast) { printf("%i\n", mast); }
Could it be that you declare the prototypes in the header files as inline? I don't think that will work, and it's possible that the compiler could complain about it.Code:int main(void) { test(5); }
- 05-14-2003 #5Linux Engineer
- Join Date
- Nov 2002
- Location
- Queens, NY
- Posts
- 1,319
file1
file2Code:#include <stdio.h> inline void test(int mast) { printf("%i\n", mast); }ResultCode:void test( int ); int main(void) { test(5); }With or without the function prototype, I get errors. I'm using gcc2.95.Code:undefined reference to `test(int)'
The best things in life are free.
- 05-14-2003 #6Linux Guru
- Join Date
- Oct 2001
- Location
- Täby, Sweden
- Posts
- 7,578
What are you doing to compile this?
- 05-14-2003 #7Linux Engineer
- Join Date
- Nov 2002
- Location
- Queens, NY
- Posts
- 1,319
Well, I'm using a make file but the commands are really nothing but
Code:g++ -Wall file.o file2.o
The best things in life are free.
- 05-14-2003 #8Linux Guru
- Join Date
- Oct 2001
- Location
- Täby, Sweden
- Posts
- 7,578
Could it be something with C++? Try this:
Code:gcc -c -o test.o test.c gcc -c -o test2.o test2.c gcc -o test test.o test2.o
- 05-15-2003 #9Linux Engineer
- Join Date
- Nov 2002
- Location
- Queens, NY
- Posts
- 1,319
Yea, this problem works fine in C. C++ however doesn't seem to like it.
The best things in life are free.
- 05-15-2003 #10Linux Guru
- Join Date
- Oct 2001
- Location
- Täby, Sweden
- Posts
- 7,578
In that case I'm afraid I can't help you. Maybe it's a compiler bug? Yes, it's hard to believe, but it might not be impossible. You could try subscribing to the gcc mailing list and ask someone there.


Reply With Quote
