inline function

I have a set of functions that I'd like to make inline using VC++ 2003. The functions are compiled sparately from the calling function.

I've attempted by placing inline before the function name and in the prototype statement but the function is not found.

Do I need to use IMPORT, extern or something like that I can't seem to find an example anywhere to emulate.

Thanks,

RON C

FUNCTION:

inline int index_4 ( int jstr, int kstr, int lstr, int i, int j, int k, int l )
{
int index;
index = ( i + j + k ) * lstr + ( i + j ) * kstr + i * jstr + l;
return( index );
}

PROTOTYPE (in another function):

inline int index_4 ( int jstr, int kstr, int lstr, int i, int j, int k, int l );

CALL TO FUNCTION:

int i = index_4 ( jstr, kstr, lstr, i, j, k, l );

ERROR FROM LINK:

dynamic_flt_arrays.obj : error LNK2001: unresolved external symbol "int __cdecl index_4(int,int,int,int,int,int,int)"
( index_4@@YAHHHHHHHH@Z)






Answer this question

inline function

  • DeepsR

    There is no easy way to tell short of getting the compiler to generate an assembly listing file:

    http://msdn.microsoft.com/library/default.asp url=/library/en-us/vccore/html/_core_.2f.fa.asp

    And then manually checking if the function was inlined or not. It is not an "error" if an inline function was not inlined - it just means that the compiler didn't think that at this specific call-site inlining the function call was not the best choice.



  • joslat

    I changed it to forced but how do I know unless I force it

    The test run times with about 1000000 calls doesn't show any difference.

    Thanks,

    RON C



  • Nate McMurtray

    I'm good at confusing people.

    I forgot to mention that there are a number of routines where the same inline routines are used. By using an #include to include the routines and not just the prototypes does the trick.

    Thanks for interest.

    RON C

    I think I can obfuscate anything as well as a politician does. Too bad for those trying to understand it.



  • supperzipper

    Sorry to be dense, but how do I know whether the compiler is inlining or compiling separate What diagnostic tells you

    RON C



  • Dennis Arthur

    If you want a function to be inlined then either the definition must be available within the same translation unit or you must compile your application with /GL - link time code-generation.

    The 'inline' keyword is just a hint to the optimizer it can choose to ignore it because, contrary to popular belief, inlining a function call can, in some cases, make your code slower: this is especially true if you tell the optimizer to optimize for size as opposed to speed. You can use the '__force_inline' keyword to tell the optimizer that you really know best but even with this keyword the optimizer my choose to ignore your request - especially if exception code is involved.

    So if you see that a funciton is not always being inlined it is probably because the optimizer has decided in some cases that it is better to leave it as a separate function.



  • CV 8.0

    including functions prior to a call site does not necessarily cause those functions to be inlined. I would suggest using __forceinline.

    Brian


  • DirkR

    Problem solved by putting the functions in a header file and then #include the header file.

    The compiling of the inline function then only takes place after it has been inserted in the code of the calling function.

    Maybe this will help someone else.

    RON C



  • Rob Clapham

    It's pretty confusing what are you doing actually. What does this mean actually

    PROTOTYPE (in another function):
    
    inline int index_4 ( int jstr, int kstr, int lstr, int i, int j, int k, int l );
    

    You can't put that in another function. If you do it's a local function declaration and it's pointeless.

    This work ok:

    inline void foo(int i)
    {
     // do something
    }
    
    inline void bar()
    {
      foo(10);
    }
    


  • inline function