This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

strange compiler error #18 (code definition with line break)

Hi,

I use Keil MicroVision (v. 5.11.1.0) for programming a Cortex-M4 microcontroller from TI.

After migrating my project from StellarisWare to TivaWare I get compiler errors for nearly equal line of code, which contains a line break.

For me it doesn't seem TI specific, so I post it here in the Keil forum.

Here is an example error:

compiling ustdlib.c...
..\..\TivaWareM4C\utils/ustdlib.h(55): error:  #18: expected a ")"
  extern int usnprintf(char * restrict s, size_t n, const char * restrict format,

The related source lines are these:

extern int usnprintf(char * restrict s, size_t n, const char * restrict format,
                     ...);

I'm not shure, why TI added a line break and what's the meaning of "...".
I don't want to modify this file (and others) of the TivaWare package, because this can cause a coders hell.

.

What's strange?

StellarisWare (the predecessor of TivaWare) also contains a file "ustdlib.c", which also has definitions with line breaks. But compiling this causes no error.

.

In direct comparison:

Line in "ustdlib.c" of StellarisWare:

extern int usnprintf(char *pcBuf, unsigned long ulSize, const char *pcString,
                     ...);

Line in "ustdlib.c" of TivaWare:

extern int usnprintf(char * restrict s, size_t n, const char * restrict format,
                     ...);

The same compiler error happens to other lines, which contains a line break.
Example:

extern float ustrtof(const char * restrict nptr,
                     const char ** restrict endptr);

.

Why I get such compiler errors after my migration to TivaWare?
Also before the migration I included the file "ustdlib.c" (including such wrapped lines) and had no errors.

If you need further information, just tell me.

Parents
  • Thanks for your time and ideas.


    The keyword "restrict" was added in C99 to help with optimization

    I remember that the TI migrating guide (from StellarisWare to TivaWare) has a note for C99.

    C99 data types are now used throughout TivaWare.
    

    By your idea I found a "C99 Mode" checkbox in the project settings and now these errors are gone.

    [IMG]http://i.imgur.com/2tXUhzs.png[/IMG]

    By the way:
    There is also a "Strict ANSI C" option, but checking this I get nearly 200 extra errors.


    From that I'll venture a guess that you only read C++, but no C. Which suggests another sanity check: you wouldn't by any chance be mixing up C++ and C compilation, would you?

    The "problematic" TivaWare file seems to be for both: C and C++.
    For your interest: Here is the "code switch" by use of preprocessor:

    //*****************************************************************************
    //
    // If building with a C++ compiler, make all of the definitions in this header
    // have a C binding.
    //
    //*****************************************************************************
    #ifdef __cplusplus
    extern "C"
    {
    #endif
    
    // ... all definitions ...
    // ... all definitions ...
    // ... all definitions ...
    
    //*****************************************************************************
    //
    // Mark the end of the C bindings section for C++ compilers.
    //
    //*****************************************************************************
    #ifdef __cplusplus
    }
    #endif
    

Reply
  • Thanks for your time and ideas.


    The keyword "restrict" was added in C99 to help with optimization

    I remember that the TI migrating guide (from StellarisWare to TivaWare) has a note for C99.

    C99 data types are now used throughout TivaWare.
    

    By your idea I found a "C99 Mode" checkbox in the project settings and now these errors are gone.

    [IMG]http://i.imgur.com/2tXUhzs.png[/IMG]

    By the way:
    There is also a "Strict ANSI C" option, but checking this I get nearly 200 extra errors.


    From that I'll venture a guess that you only read C++, but no C. Which suggests another sanity check: you wouldn't by any chance be mixing up C++ and C compilation, would you?

    The "problematic" TivaWare file seems to be for both: C and C++.
    For your interest: Here is the "code switch" by use of preprocessor:

    //*****************************************************************************
    //
    // If building with a C++ compiler, make all of the definitions in this header
    // have a C binding.
    //
    //*****************************************************************************
    #ifdef __cplusplus
    extern "C"
    {
    #endif
    
    // ... all definitions ...
    // ... all definitions ...
    // ... all definitions ...
    
    //*****************************************************************************
    //
    // Mark the end of the C bindings section for C++ compilers.
    //
    //*****************************************************************************
    #ifdef __cplusplus
    }
    #endif
    

Children
  • The construct:

    #ifdef __cplusplus
    extern "C"
    {
    #endif
    


    will only make sure that a C++ compiler will correctly follow the C standard for external symbol names when linking, so that the C++ program can access C functions available in object files or libraries.

    The above construct does not take into account syntactic changes between C and C++, such as differences in reserved keywords etc.

    So using a C++ compiler that doesn't support "restricted" you would need:

    #ifdef __cplusplus
    #define restricted
    #endif
    


    to make sure that your C compiler sees the keyword and your C++ compiler doesn't see it.