473,396 Members | 2,082 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Help with #define

I have two preprocessing macros defined in my program:

#define SetBooleanAttribute(str, attr) else if(key->Equals(str)) \
##attr## = (settings->Attributes["value"]->Value=="true" ? true :
false);
#define SetStringAttribute(str, attr) else if(key->Equals(str)) \
##attr## = settings->Attributes["value"]->Value;

Then in my code I have the following:

1: if(key->Equals("version"))
2: this->version = settings->Attributes["value"]->Value;
3: SetStringAttribute("mode", this->mode);
4: SetStringAttribute("path", this->path);
5: else
6: MessageBox::Show("Unknown setting.", "Unknown",
MessageBoxButtons::OK);

But when I try to compile my program, the compiler states that I have
an invalid else without matching if on line 4, yet it seemed to handle
line 3 just fine.

What am I doing wrong?

Evan

May 31 '07 #1
2 1273
You have a semicolon in your macro expansion and one coming from the main
line of code. This close the if statement (without brace onlu one
instruction can be present). Remove the semicolon in the macro definition.

Your expansion look like:

if (cond) statement ;
else if (cond) statement ; ; <-- this is a second null statement after your
if (closing it)
else if (cond) statement ; ;

<ew******@gmail.comwrote in message
news:11**********************@h2g2000hsg.googlegro ups.com...
>I have two preprocessing macros defined in my program:

#define SetBooleanAttribute(str, attr) else if(key->Equals(str)) \
##attr## = (settings->Attributes["value"]->Value=="true" ? true :
false);
#define SetStringAttribute(str, attr) else if(key->Equals(str)) \
##attr## = settings->Attributes["value"]->Value;

Then in my code I have the following:

1: if(key->Equals("version"))
2: this->version = settings->Attributes["value"]->Value;
3: SetStringAttribute("mode", this->mode);
4: SetStringAttribute("path", this->path);
5: else
6: MessageBox::Show("Unknown setting.", "Unknown",
MessageBoxButtons::OK);

But when I try to compile my program, the compiler states that I have
an invalid else without matching if on line 4, yet it seemed to handle
line 3 just fine.

What am I doing wrong?

Evan

Jun 1 '07 #2
Oye, that was dumb of me. Thank you.

Evan

On May 31, 11:44 pm, "Luc E. Mistiaen"
<luc.misti...@advalvas.be.no.spamwrote:
You have a semicolon in your macro expansion and one coming from the main
line of code. This close the if statement (without brace onlu one
instruction can be present). Remove the semicolon in the macro definition.

Your expansion look like:

if (cond) statement ;
else if (cond) statement ; ; <-- this is a second null statement after your
if (closing it)
else if (cond) statement ; ;

<ewpat...@gmail.comwrote in message

news:11**********************@h2g2000hsg.googlegro ups.com...
I have two preprocessing macros defined in my program:
#define SetBooleanAttribute(str, attr) else if(key->Equals(str)) \
##attr## = (settings->Attributes["value"]->Value=="true" ? true :
false);
#define SetStringAttribute(str, attr) else if(key->Equals(str)) \
##attr## = settings->Attributes["value"]->Value;
Then in my code I have the following:
1: if(key->Equals("version"))
2: this->version = settings->Attributes["value"]->Value;
3: SetStringAttribute("mode", this->mode);
4: SetStringAttribute("path", this->path);
5: else
6: MessageBox::Show("Unknown setting.", "Unknown",
MessageBoxButtons::OK);
But when I try to compile my program, the compiler states that I have
an invalid else without matching if on line 4, yet it seemed to handle
line 3 just fine.
What am I doing wrong?
Evan

Jun 1 '07 #3

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

Similar topics

6
by: wukexin | last post by:
Help me, good men. I find mang books that introduce bit "mang header files",they talk too bit,in fact it is my too fool, I don't learn it, I have do a test program, but I have no correct doing...
13
by: webzila | last post by:
Hello, I have to write a program for an 8051 micro-controller using micro-C to monitor Switch 1 and if the switch in pushed the message "switch 1 pushed" should be displayed in the LCD. Also the...
1
by: Paul Ferrill | last post by:
Can anyone help with the code to call the following C routines: /* Memory model that allows to access memory at offsets of lzo_uint. */ #if !defined(__LZO_MMODEL) # if (LZO_UINT_MAX <=...
20
by: paolo.arimado | last post by:
Dear everyone, Can someone please help me on my HW. I'm trying to write a program that will display the following: * *** ***** ******* *********
9
by: Jerret Johnson | last post by:
A challenged co-worker of mine challenged me to come up with a perverse example of a conforming Standard C program. This is by no means a gold medal winner in a C obfuscation contest, but...
8
by: aaron | last post by:
I have an array of id=>category: =Automotive Parts =Automotive Parts\Domestic =Automotive Parts\Foreign =Building Supplies =Building Supplies\Lumber =Building Supplies\Lumber\Hardwood ...
5
by: weidongtom | last post by:
Hi, I tried to implement the Universal Machine as described in http://www.boundvariable.org/task.shtml, and I managed to get one implemented (After looking at what other's have done.) But when I...
5
by: iapx86 | last post by:
My parser project calls for a computed goto (see code below). The C preprocessor delivers the desired result, but is ugly. Template metaprogramming delivers results I do not understand. Can...
11
by: A.C. | last post by:
hi i m declaring a structure globally & there is func1 & main. i m assigning the value to variable(this is a pointer) of structure in fun1 & want to print it in main. this is same kind of...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.