How to solve "expected an expression" error?

Posted on 2013-05-15
Last Modified: 2013-05-24
I'm using Keil tools uVision V4.71.2.0.  C compiler Armcc.Exe version V5.03.0.69.
I'm working on large code base.

The following is the error from the compiler:

Build target 'Proj1_Debug'
compiling RTX_Config.c...
C:\Keil\ARM\RV31\INC\RTX_lib.c(185): error: #29: expected an expression
Target not created

Line 185 in RTX_lib.c is as follows:

#if (__ARM__ && __RTA_RTX_CONFIG)

what might be the problem?
Question by:naseeam
  • 2
  • 2
LVL 35

Expert Comment

ID: 39170051
Can you post some of the code either side of that line too?

Author Comment

ID: 39171384
I think I found the problem.

Filename RTX_lib.c has the #if condition as follows:

#if (__ARM__ && __RTA_RTX_CONFIG)     // error is "expected an expression"

Filename RTX_Config.c has the following definition:

#define __RTA_RTX_CONFIG

Now, this error makes sense. Since __RTA_RTX_CONFIG is empty, there is no expression.
But I cannot understand how RTX_lib.c knows about __RTA_RTX_CONFIG because it's defined
in a different .c file?

I'm new to some large code base which uses Keil Development Tool based on ARM 7 Processor.
LVL 33

Accepted Solution

sarabande earned 500 total points
ID: 39171438
the error means that the #if was not expected at this point but an "expression", for example somewhat like that what comes after the #if. you also would get a similar message if you have a sequence #if #if somewhere in the code. such sequence could happen if an expression between the #if keywords resolves to an empty string.

such an error means that some (or all) of the lines before could not be precompiled correctly, what can happen if precompiler statements were not correctly nested before (for example if a #endif was missing). if that happens in a file that comes with a foreign libray it is not likely that they actually made a mistake with nesting, at least not if you were using the original platform for which the source was designed. on a different platform, say a 64-bit platform or a realtime environment which could be different from that the original source was developed on, it could be that your environment activated a preprocessor branch that was not fully tested by the developer and therefore caused the errors. sometimes those errors occur because of wrongly defined preprocessor macros or missing preprocessor macros. to solve the error you should check all lines before with an editor that shows which parts before the error line were active and which were not. you might be able then to find out what was wrong with the part before if you examine all #if... statements which were active and by checking for correct nesting and if the conditions could be true (or were valid) for your environment.


Author Comment

ID: 39171651
The file compiles now and I can build my target.  What I don't understand is how does RTX_lib.c knows the value of __RTA_RTX_CONFIG macro.  This macro is defined in a different C file.  

I'm using Keil uVision V4.71.2.0 operating system.  It seems like lot of things are happening behind scenes.  RTX_lib.c is Keil's operating system file.  This operating system is in my hard drive.
LVL 33

Expert Comment

ID: 39171694
such macros also can be passed from outside to the compiler either by command (normally with -D<macro>) or by makefile/projectfile option. some macros also may be set by the compiler, for example macros specifying the operation system and version numbers.


Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
Jaspersoft Studio is a plugin for Eclipse that lets you create reports from a datasource.  In this article, we'll go over creating a report from a default template and setting up a datasource that connects to your database.
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

808 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question