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 functions, C for MSP430

Other Parts Discussed in Thread: MSP430F1611

A simple question (I hope),

I can not get the MSP430 C-compiler to compile inline functions.

'inline' is recognized as a keyword by the IDE editor.  But the compiler does not recognize this keyword.

 

Am I missing a compiler flag/switch or something lse I must setup in the CCSv4?   (Same results with __inline).

 

Thanks,

Bob Strother

 

  • Bob,

    Does the compiler fail to build or do you see in the disassembly view that the function was not inlined?

    Just as a cleanup check, check the inline usage guidelines in section 2.11 and restrictions shown in section 3.7 of the MSP430 Compiler User's guide (link here).

    Also, I will move this thread to the compiler forum, so the experts there can have additional insights.

    Regards,

    Rafael

  • Rafael,


    Thanks for the fast response / forwarding.  The compiler flags the whole block as an error based on the illegal/unrecognized keyword "inline".

    e.g.

    inline get_time( );

    xxxxxx

    inline void get_time( void)

    {

    xxxx

    }

     

    Thnaks,

    Bob Strother

     

  • What is the exact error message you are getting?

    The code snippet in your message would get into trouble because the declaration (which implicitly returns type int) and the definition (which returns void) do not match.  But I suspect that was just a typo.  Fixing that makes the snippet compile correctly.

    If you are compiling with the --strict_ansi (-ps) option then "inline" would not be recognized as a keyword, although "__inline" (two underscores) would.

     

  • OK,

     

    In this case the target is the MSP430F1611.  I get the same error messages with 'inline' or '__inline' (two underscores).

    I get no error from the function prototype declaration "inline void toggle_led( void );" or from the definition of the function

    "inline void toggle_led( void )
    {
        P1OUT ^= 0x03;                      // Toggle P1.0 using exclusive-OR
    }"

    I get two errors: 

    ""inline" is not allowed"  and
    "declaration may not appear after executable statement in block "

    when the function is called:

    inline void toggle_led();

     

    The console text (command line and errors) follows:

    **** Build of configuration Debug for project MSP430-flash1 ****

    C:\Program Files (x86)\Texas Instruments\ccsv4\utils\gmake\gmake -k all
    'Building file: ../main.c'
    'Invoking: Compiler'
    "C:/Program Files (x86)/Texas Instruments/ccsv4/tools/compiler/MSP430 Code Generation Tools 3.2.3/bin/cl430" --silicon_version=msp -g --include_path="C:/Program Files (x86)/Texas Instruments/ccsv4/msp430/include" --include_path="C:/Program Files (x86)/Texas Instruments/ccsv4/tools/compiler/MSP430 Code Generation Tools 3.2.3/include" --diag_warning=225 --printf_support=minimal --preproc_with_compile --preproc_dependency="main.pp"  "../main.c"
    "../main.c", line 50: error: declaration may not appear after executable statement in block
    "../main.c", line 50: error: "inline" is not allowed
    "../main.c", line 50: warning: function "toggle_led" was declared but never referenced
    "../main.c", line 38: warning: variable "temp" was set but never used
    2 errors detected in the compilation of "../main.c".

    >> Compilation failure
    C:\Program Files (x86)\Texas Instruments\ccsv4\utils\gmake\gmake: *** [main.obj] Error 1
    C:\Program Files (x86)\Texas Instruments\ccsv4\utils\gmake\gmake: Target `all' not remade because of errors.
    Build complete for project MSP430-flash1

     

    The "temp" is a variable I was using for debugging and it was never used.

     

    Thanks for your help,

    Bob

     

     

  • Are you saying that the expression you use to call your function is literally "inline void toggle_led();"?  If so, that's the error.  A call should be simply "toggle_led();" -- the inline keyword and return type are part of the declaration and definition.  If "inline void toggle_led();" appears in a function body, it is syntactically a function declaration, which explains the error messages.

    A function declared inline is no different than any other function in declaration, definition, or use.  The "inline" keyword on the definition tells the compiler it may inline calls to the function;  otherwise, it behaves like any non-inline function.

  • pf,

     

    Thanks.  That was it.

    It really was that simple.  I didn't realize that the inline keyword was only required for the function declaration / definition.

    Thanks.   Good, fast help.

     

    Bob