We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
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:
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.
If the compiler doesn't understand the "restrict" keyword, then I would see it generate interesting error messages when it thinks it sees _two_ parameter names after each other instead of seeing a ',' or a ')'.
The keyword "restrict" was added in C99 to help with optimization by telling the compiler that there is no pointer aliasing it need to worry about.
The meaning of ... is that the function can take zero or more extra parameters. It's a variadic function.
I'm almost certain the line breaks have nothing to do with this. The "restrict" keyword in the newer source code, OTOH, might.
I'm not shure [...] what's the meaning of "...".
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?
I don't want to modify this file (and others) of the TivaWare package, because this can cause a coders hell.
You don't have to make such modifications permanently. But you really should try what effects modifications have. Do them to copies of the files, and use those in a testing copy of the project at hand.
If the compiler doesn't support "restrict", then the easiest route is to add:
#define restrict
and have the preprocessor strip the keyword.
As already noted, the first task is to figure out why the compiler complains. Then it's possible to decided on what is the best permanent solution.
about newlines - you can have newlines almost everywhere in C/C++, between tokens/keywords.
It's basically only in one-line comments, preprocessor declarations and inside strings you can't have any newline.
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.
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
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.