Find the answer to your Linux question:
Page 1 of 2 1 2 LastLast
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.
  1. #1
    Linux 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.

  2. #2
    Linux 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.

  3. #3
    Linux 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.

  4. $spacer_open
    $spacer_close
  5. #4
    Linux Guru
    Join Date
    Oct 2001
    Location
    Täby, Sweden
    Posts
    7,578
    Can you give an example? This worked perfectly for me:
    File 1:
    Code:
    #include <stdio.h>
    
    inline void test&#40;int mast&#41;
    &#123;
        printf&#40;"%i\n", mast&#41;;
    &#125;
    File 2:
    Code:
    int main&#40;void&#41;
    &#123;
        test&#40;5&#41;;
    &#125;
    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.

  6. #5
    Linux Engineer
    Join Date
    Nov 2002
    Location
    Queens, NY
    Posts
    1,319
    file1
    Code:
    #include <stdio.h>
    
    inline void test&#40;int mast&#41;
    &#123;
        printf&#40;"%i\n", mast&#41;;
    &#125;
    file2
    Code:
    void test&#40; int &#41;;
    
    int main&#40;void&#41;
    &#123;
        test&#40;5&#41;;
    &#125;
    Result
    Code:
    undefined reference to `test&#40;int&#41;'
    With or without the function prototype, I get errors. I'm using gcc2.95.
    The best things in life are free.

  7. #6
    Linux Guru
    Join Date
    Oct 2001
    Location
    Täby, Sweden
    Posts
    7,578
    What are you doing to compile this?

  8. #7
    Linux 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.

  9. #8
    Linux 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

  10. #9
    Linux 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.

  11. #10
    Linux 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.

Page 1 of 2 1 2 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •