473,763 Members | 1,883 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Macro expansion in armcc

there's a MACRO call :

MACRO1(cnf)

and its expansion is :

#define MACRO1(cnf) (((cnf) != TRUE)? (CLEANUP(FAIL)) :(err =
SUCCESS));

#define CLEANUP(a)
\
{
\
if ((err = (a)) != SUCCESS)
\
{
\
goto cleanup;
\
}
\
}
\
Its giving me error:
line 392: Error: expected an expression
MACRO1(cnf)
^

Same code is getting compiled in gcc but armcc gives the above error..
Can anybody pls comment on this?

Jul 11 '06 #1
2 3493
sr*******@gmail .com wrote:
there's a MACRO call :

MACRO1(cnf)

and its expansion is :

#define MACRO1(cnf) (((cnf) != TRUE)? (CLEANUP(FAIL)) :(err =
SUCCESS));
I assume that in your code it's all on one line; if not, it should have
given an error for this declaration, not for your call.
#define CLEANUP(a)
{
if ((err = (a)) != SUCCESS)
{
goto cleanup;
}
}
Ditto here; you provided line continuation backslashes, but they
themselves had wrapped to the next line. I've snipped them here for
brevity.
Its giving me error:
line 392: Error: expected an expression
MACRO1(cnf)
^
The CLEANUP macro is declared to be equivalent to an entire block
statement containing an if statement. However, in MACRO1, you use it
essentially like this:

value? CLEANUP(FAIL): expr;

In ISO C, the ternary operator takes three expressions, not one
expression and three bits of whatever executable code. IOW, this:

value? { if (x) y; }: expr;

is invalid, but that is what you are declaring.

Since your CLEANUP macro involves a goto statement (see the castigations
for that flying in from a dozen posters, btw), you can't turn CLEANUP
itself into a ?: expression, which would have solved this problem; so
you're left with only one solution: change your MACRO1 to use an if
statement as well, so that you get something like

if (!cnf) {
if ((err=FAIL)!=SU CCESS) { goto cleanup; }
} else err=SUCCESS;

It's still ugly, and you will probably want to consult the FAQ on how to
write a statement macro more solidly, but it should work - FSVO.
Same code is getting compiled in gcc but armcc gives the above error..
That's because gcc supports complete statements in ?: (and IIRC in all
expression contexts). Beats me why; its main use is to create illegible
code.

Richard
Jul 11 '06 #2
sr*******@gmail .com writes:
there's a MACRO call :

MACRO1(cnf)

and its expansion is :

#define MACRO1(cnf) (((cnf) != TRUE)? (CLEANUP(FAIL)) :(err =
SUCCESS));

#define CLEANUP(a)
\
{
\
if ((err = (a)) != SUCCESS)
\
{
\
goto cleanup;
\
}
\
}
\
Its giving me error:
line 392: Error: expected an expression
MACRO1(cnf)
^

Same code is getting compiled in gcc but armcc gives the above error..
Can anybody pls comment on this?
I see a number of problems.

As Richard Bos has mentioned, some of your lines wrapped when you
posted this.

Stylistically, there's way too much vertical space in the definition
of CLEANUP, and some of the '\'s wrapped to the next line.

It's easy enough to fix the lin wrapping in MACRO1, either by
re-joining the line or by splitting it and adding a '\'.

Here's a re-formatted version of CLEANUP:

#define CLEANUP(a) \
{ \
if ((err = (a)) != SUCCESS) \
{ \
goto cleanup; \
} \
}

I presume TRUE is defined somewhere else. It's almost never a good
idea to compare a boolean expression for equality with TRUE or FALSE.
Remember than an expression with the value zero is considered false
when used as a condition, and an expression with *any* non-zero value
is considered true. Your test
((cnf) != TRUE)
will fail if cnf is true (non-zero) but doesn't happen to have the
same value as TRUE (presumably 1). cnf is already a condition; just
use it directly. ((cnf) != TRUE) can be replaced by (!(cnf)). See
section 9 of the comp.lang.c FAQ, <http://www.c-faq.com/>.

A macro usually expands to either an expression or a statement. An
expression can be used as a statement by adding a ';', but a statement
cannot be used in an expression context.

Your MACRO1 definition *almost* expands to an expression, but you've
added a semicolon, so you can't use MACRO1 in an expression context.
That's what the error message is telling you.

I might define MACRO1 something like this:

#define MACRO1(cnf) ( (cnf) ? err = SUCCESS : CLEANUP(FAIL) )

(but I'd give it a better name!)

Your CLEANUP macro expands to a compound statement. This means, of
course, that you can't use it in an expression context. Presumably
you haven't made that mistake, but since you only showed us the
definitions of your macros and not the code that invokes them, we
can't really tell. But there's still a problem using CLEANUP even in
a statement context; see question 10.4 in the FAQ.

--
Keith Thompson (The_Other_Keit h) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Jul 11 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
2076
by: Caleb Hattingh | last post by:
Hi Here is a script I want to be able to write (explanation appears after): *** start of script *** import MyCustomMacroLib # This does the magic I would like help for. # This is not python, but the module imported above # will use this block internally and prevent it
1
1627
by: me | last post by:
Hi guys I want to insert a load of pieces of data into a map The map has an std::string representing a field name as the key, and the value is a struct with 2 members - the field length and a bool indicating whether the field is a special field or not. The struct representing the value has a constructor that takes a single parameter for the length, and defaults the boolean to false.
3
2543
by: Ark | last post by:
Hello, NG, Please, help on this snippet: #define CAT(a,b) a##b #define COMMENT CAT(/,/) COMMENT This is a comment Should it compile? It passes MS C/C++ 13.0 (Visual Studio 2002) and fails IAR ARM compiler.
7
3500
by: reppisch | last post by:
Hi Ng, i am looking for a method of expanding a macro while the rest of the code remains untouched. I have some code which does macro voodo / ifdef's which i would like to strip and simplify. The Faq pointed me to scpp but i could not compile it. the lex.c generated by flex 2.5.4 is broken.
4
3690
by: ImOk | last post by:
I come from the Visual Foxpro world, which is one reason I love PHP. VFP is a scripting type language with macro substitution abilities similar to PHP. Besides the regular expansion I can do crazy things (VFP uses & instead of $): x="sales" sales="1000" salestax="8.25"
3
2008
by: casul | last post by:
Hi All, I was told there were a few macro gurus on this group :) I'm trying to define a macro that will allow me to write the following code : #include MY_MACRO( NAME, SPACE )
0
1210
by: borophyll | last post by:
Hi all Can anyone explain to me the algorithm for macro expansion in the C++ preprocessor. I am confused why the following code works like it does: #define A(x) #x #define B(x) A(x) #define TEST 1
1
3380
by: todWulff | last post by:
Good day folks. Let me open with the statement that I am not a C++/C programmer. The environment that I am programming in is ARMbasic, an embedded BASIC targeted toward ARM-based micro-controllers. So why am I posting herein? Well, the ARMbasic environment makes use of a tool borrowed from your folk's environment - CPP. The build details are: C:\Program Files\Coridium>cpp --version cpp (GCC) 3.2.3 (mingw special 20030504-1) Copyright...
5
1780
by: Srinivas Mudireddy | last post by:
Hi, We have bunch of message levels and depending on whether that level is turned on, messages of that level are printed. For example, we have levels like MSG_LOW, MSG_MED etc. We want to provide a wrapper API on top of this to print various kinds of messages and map the wrapper API to either MSG_LOW or MSG_MED. For example, our wrapper API have macros such as MSG_FUNCTION_ENTRY, MSG_FUNCTION_EXIT, MSG_STATE_CHANGE, MSG_INVALID_INPUT...
0
10003
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8825
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7370
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6643
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5271
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5410
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3918
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3529
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2797
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.