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

Hi,

What is the good way to inline function in CCS? Define/declare as inline void ? use static qualifier? The user's guide doesn't help me.

I have several inlined functions in my code and the compiler *sometime* warns: 

#179-D function "UARTTx" was declared but never referenced (resource: UART.c)

Some other function defined/declared/called exactlly with the same way compile without warning.

Thank you.

  • The warning comes before inlining is even considered.  Unless there is something very strange, it means what it says:  the function is present in the file but is not called, and is probably declared static and can't be called from any other file either.

    As for inlining, the compiler will automatically inline some functions, generally small ones, depending on your compilation options.  The optimisation level must be at least -o3 for automatic inlining.  The "inline" keyword will lead the compiler to inline calls to that function, as long as the result doesn't exceed certain limits;  the optimisation level must be at least -o0 for the "inline" keyword to be effective.  The source of the inlined call must be visible at the point of call, thus in the same file or one included in it.

    "Void" is a type;  its use as the return type of a function does not affect inlining.  The static qualifier doesn't directly affect inlining, but it may affect whether the compiler is able to eliminate the original function entirely if all calls are inlined.

    If you have a problem that these hints don't answer, we'll need to see a test case with which we can reproduce the issue before we can give you a better answer.

  • Today I also updated CCS + MSP Compiler, the compiler seems to be happy with my inlined functions but I would like to be sure: is it correct (and is it the best way) to write :

    @main.c

    #include func.h   // may be included in other c files

    int main(void) 

    {

       int bar;

       bar = foo(42); // foo may be called in other c files

       ...

    }

    @func.h

    #ifndef __BAR_H__

    #define __BAR_H__

    static inline int foo (int data)

    {

       return data+1;

    }

    #endif

  • That looks fine.  You get a diagnostic when you include this func.h?  We have to reproduce that ourselves before we can comment.  Please submit a test case as described in the last part of the forum guidelines.

    Thanks and regards,

    -George

  • Hi eveyone, 

    I wonder something about static inline, how can I call it from another source or header file? I wonder because it is static?

    can you give me some information static inline please??

    for example, I invastegated foc control software which is written by ti team,

    @proj_lab11e.c

    interrupt void mainISR(void)

    {

    .

    .

        CLARKE_run(clarkeHandle_I,&gAdcData.I,&Iab_pu);

       ...

    }

    @clarke.h

    ..

    .

    static inline void CLARKE_run(CLARKE_Handle handle,const MATH_vec3 *pInVec,MATH_vec2 *pOutVec){

    ...

    }

    I think I can't call static fonk from another file..

    best regards..

  • umit GULER said:
    I wonder something about static inline, how can I call it from another source or header file?

    For any function to be inlined, the compiler has to see the full source to the function.  So, put a static inline function in a header file.  

    Thanks and regards,

    -George