This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Inline Function usage in other c-file



Hello,

is it possible to declare a function as inline for external usage in another module?
(using TI compiler for C28). I want to inline a function in other c-sources as well.

What is the best way to do this? Couldn't find any relevant help in SPRU514

I tried it out but ended up with the compiler error #115 function foo was referenced but not defined

moduleA.c

inline int foo(int x)
{
....
}

moduleA.h

extern inline int foo(int x);

Best regards,
Stefan

  • Hello Stefan,

    the functions declared as inline are local into the scope of the file where they are declared and these functions are hidden from the other files. It's like a declaration static for a name (for example, refer please:  Ira Pohl. University of California Santa Cruz. Object-Oriented Programming using C++).

    Regards,

    Igor

  • Hello Igor,

    I don't think it is that simple. I have used inline functions with a gnu compiler (tricore) with extern prototypes and it inlined these functions in every translation unit (c object file) in the place where I called this function. Similar to global macro definition.

    I think it is a little bit compiler specific how it supports function inlining, although the C99 standard describes ways to call inline functions with extern prototypes: http://www.greenend.org.uk/rjk/tech/inline.html

    Regards,
    Stefan

  • Hi Stefan,

    Did you try go through that link at SPRU514F?

    6.15 GNU Language Extensions
    The GNU compiler collection (GCC) defines a number of language features not found in the ANSI/ISO C
    and C++ standards. The definition and examples of these extensions (for GCC version 4.7) can be found
    at the GNU web site, http://gcc.gnu.org/onlinedocs/gcc-4.7.2/gcc/C-Extensions.html#C-Extensions.
    Most of these extensions are also available for C++ source code.

    Through above link you can find "Inline" link http://gcc.gnu.org/onlinedocs/gcc-4.7.2/gcc/Inline.html#Inline

    I have tried to apply this with -gcc option and I have called the function inc(int* a) within another file, but C28x compiler (6.1.0) has generated an error message:

    unresolved symbol _inc :-(

    at the same time the function body is displayed by CCS editor when the cursor is on the function call. 

    Maybe TI employees will clarify this issue...

    Regards,

    Igor

  • Stefan Buechner said:
    is it possible to declare a function as inline for external usage in another module?

    (using TI compiler for C28). I want to inline a function in other c-sources as well.

    What is the best way to do this? Couldn't find any relevant help in SPRU514

    The closest you will come is described in the section titled Guarded Inlining and the _INLINE Preprocessor Symbol in the C2000 compiler manual.  The information there is accurate, but the actual implementation in the current compiler RTS is more evolved.  It is conceptually similar, especially in how it uses _INLINE.  To see how it is done currently, look at the files string.h and strlen.c in the zip file compiler install root/lib/rtssrc.zip.

    Thanks and regards,

    -George

  • @George,

    thanks for the reply. Sorry, I found that section you highleighted italic in the SPRU514 compiler handbook but didn't read it carefully. They declare and implement the library functions in the header files. That's a way to go, I have tried it out. I guess the optimization will throw away unused static functions.

    @Igor,

    I also have tried the --gcc option (Project Properties / Build / C2000 Compiler / Advanced Options / Language Options / Enable support for GCC extensions) but didn't have succes either. Description is in section 6.15.1 in SPRU514 as your already found.

    I guess I have to live with it that the TI compiler is not fully compatible with the gcc extension.

    Regards,
    Stefan

  • yes, Stefan,

    I have  faced  not the first time with similar issues. It seems GNU extension support has quite conditional character...

    Regards,

    Igor