473,763 Members | 8,483 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

is it possible to write such a macro?

#define ONCFILE_ERR1(fu ncname, name) \
{ \
#ifdef DEBUG\
cerr << __FILE__ << ":" << __LINE__ << " duplicated call to " <<
funcname << " " << name << endl; \
#endif \
}
I want to have conditional macros inside a macro. When I compile this
code, the error message is:
ONetCDFFile.cpp :14:2: '#' is not followed by a macro parameter

Any idea how I should proceed with this?

Mar 24 '06 #1
7 23549
another question about macro, how do i force a return at the end of
each macro line?
it seems the end result of multi-line macro always colapse into a
single line...

fe*****@gmail.c om wrote:
#define ONCFILE_ERR1(fu ncname, name) \
{ \
#ifdef DEBUG\
cerr << __FILE__ << ":" << __LINE__ << " duplicated call to " <<
funcname << " " << name << endl; \
#endif \
}
I want to have conditional macros inside a macro. When I compile this
code, the error message is:
ONetCDFFile.cpp :14:2: '#' is not followed by a macro parameter

Any idea how I should proceed with this?


Mar 24 '06 #2
fe*****@gmail.c om wrote:
#define ONCFILE_ERR1(fu ncname, name) \
{ \
#ifdef DEBUG\
cerr << __FILE__ << ":" << __LINE__ << " duplicated call to " <<
funcname << " " << name << endl; \
#endif \
}
I want to have conditional macros inside a macro. When I compile this
code, the error message is:
ONetCDFFile.cpp :14:2: '#' is not followed by a macro parameter

Any idea how I should proceed with this?


Your code is C++, so asking in comp.lang.c++ is
better than here. However I don't think the preprocessor
is different. Think about how \ works with lines being
spliced together. Your #ifdef is in the
middle of a line... However you
could achieve what you want above with

#ifdef DEBUG
#define ONCFILE_ERR1(fu ncname, name) \
{ some code; }
#else
#define ONCFILE_ERR1(fu ncname,name)
#endif

-David

Mar 24 '06 #3
fe*****@gmail.c om wrote:
#define ONCFILE_ERR1(fu ncname, name) \
{ \
#ifdef DEBUG\
cerr << __FILE__ << ":" << __LINE__ << " duplicated call to " <<
funcname << " " << name << endl; \
#endif \
}
I want to have conditional macros inside a macro. When I compile this
code, the error message is:
ONetCDFFile.cpp :14:2: '#' is not followed by a macro parameter

Any idea how I should proceed with this?

Turn it inside out...

#ifdef DEBUG
#define ONCFILE_ERR1(fu ncname, name) \
cerr << __FILE__ << ":" << __LINE__ << " duplicated call to " \
<< funcname << " " << name << endl
#else
#define ONCFILE_ERR1(fu ncname, name)
#endif

HTH,
--ag

--
Artie Gold -- Austin, Texas
http://goldsays.blogspot.com
"You can't KISS* unless you MISS**"
[*-Keep it simple, stupid. **-Make it simple, stupid.]
Mar 24 '06 #4
Thank you for your reply..sorry about the c++ code although my point is
really just the preprocessing macro. Your suggestions work for this
simple macro, what if I have something more complicated such as

#define macro1
do stuff
#ifdef c1
do something
#endif
do stuff
#ifdef c2
do something else
#endif
.....
#endif /* macro1 */

as you can see, if it's possible to embed "#ifdef" etc inside #define,
things are much easier. Is this possible?

Fei
David Resnick wrote:
fe*****@gmail.c om wrote:
#define ONCFILE_ERR1(fu ncname, name) \
{ \
#ifdef DEBUG\
cerr << __FILE__ << ":" << __LINE__ << " duplicated call to " <<
funcname << " " << name << endl; \
#endif \
}
I want to have conditional macros inside a macro. When I compile this
code, the error message is:
ONetCDFFile.cpp :14:2: '#' is not followed by a macro parameter

Any idea how I should proceed with this?


Your code is C++, so asking in comp.lang.c++ is
better than here. However I don't think the preprocessor
is different. Think about how \ works with lines being
spliced together. Your #ifdef is in the
middle of a line... However you
could achieve what you want above with

#ifdef DEBUG
#define ONCFILE_ERR1(fu ncname, name) \
{ some code; }
#else
#define ONCFILE_ERR1(fu ncname,name)
#endif

-David


Mar 24 '06 #5
fe*****@gmail.c om wrote:
Thank you for your reply..sorry about the c++ code although my point is
really just the preprocessing macro. Your suggestions work for this
simple macro, what if I have something more complicated such as

#define macro1
do stuff
#ifdef c1
do something
#endif
do stuff
#ifdef c2
do something else
#endif
....
#endif /* macro1 */

as you can see, if it's possible to embed "#ifdef" etc inside #define,
things are much easier. Is this possible?

No.

--ag

--
Artie Gold -- Austin, Texas
http://goldsays.blogspot.com
"You can't KISS* unless you MISS**"
[*-Keep it simple, stupid. **-Make it simple, stupid.]
Mar 24 '06 #6
fe*****@gmail.c om schrieb:
#define ONCFILE_ERR1(fu ncname, name) \
{ \
#ifdef DEBUG\
cerr << __FILE__ << ":" << __LINE__ << " duplicated call to " <<
funcname << " " << name << endl; \
#endif \
}
I want to have conditional macros inside a macro. When I compile this
code, the error message is:
ONetCDFFile.cpp :14:2: '#' is not followed by a macro parameter

Any idea how I should proceed with this?


The workaround already has been stated; back to the issue:
- Preprocessing directives can only span one line (the \ may hide
that but the above is only one source line) and there may be only
one preprocessing directive per line.
- Preprocessing directives start the respective line (but for
whitespace)
- Thus, you cannot generate preprocessing directives using
preprocessing directives; the language does not allow it.

The reason for the error message is another one:
The preprocessor assumes that the # is the "stringize" preprocessor
operator; this operator surrounds the passed argument by double
quotes ("), i.e. makes them into string literals.

Cheers
Michael
--
E-Mail: Mine is an /at/ gmx /dot/ de address.
Mar 24 '06 #7
"fe*****@gmail. com" wrote:
fe*****@gmail.c om wrote:

#define ONCFILE_ERR1(fu ncname, name) \
{ \
#ifdef DEBUG\
cerr << __FILE__ << ":" << __LINE__ << " duplicated call to " <<
funcname << " " << name << endl; \
#endif \
}

I want to have conditional macros inside a macro. When I compile
this code, the error message is:
ONetCDFFile.cpp :14:2: '#' is not followed by a macro parameter

Any idea how I should proceed with this?


another question about macro, how do i force a return at the end
of each macro line? it seems the end result of multi-line macro
always colapse into a single line...


Don't toppost. Your answer (or continuation) belongs after (or
intermixed with) the material you quote, after snipping irrelevant
material. I fixed this one.

You can't do that.

Ignoring the C++, and just considering macros (which are common to
C++ and C). By definition a macro (the part after the #define)
ends on the same line. This can be partially ameliorated by the
use of continuation lines (where the last character on the physical
line is a '\'). You CANNOT put preprocessing conditionals inside a
macro, because they have to start a line, and you can't get there
without ending the macro definition.

The usual trick to form multiline macros is the following:

#define MULTILINEMACRO \
do { \
statement1; \
statement2; \
} while (0)

Notice no final semicolon. The limit is the maximum input line the
compiler can handle, which is guaranteed about 500 for C90. Look
it up. This behaves properly for all macros that do not have to
return a value.

In future please ask C++ questions on c.l.c++, and C questions on
c.l.c. Don't toppost on either newsgroup.

--
Read about the Sony stealthware that is a security leak, phones
home, and is generally illegal in most parts of the world. Also
the apparent connivance of the various security software firms.
http://www.schneier.com/blog/archive...drm_rootk.html
Mar 25 '06 #8

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

Similar topics

25
3256
by: Andrew Dalke | last post by:
Here's a proposed Q&A for the FAQ based on a couple recent threads. Appropriate comments appreciated X.Y: Why doesn't Python have macros like in Lisp or Scheme? Before answering that, a clarification on what 'macro' means. A Lisp macro is a way of modifying code when that code is first defined. It can rearrange the structure of the code, and add and remove parts of it. Unlike C's #define macro language, Lisp macros understand the...
699
34118
by: mike420 | last post by:
I think everyone who used Python will agree that its syntax is the best thing going for it. It is very readable and easy for everyone to learn. But, Python does not a have very good macro capabilities, unfortunately. I'd like to know if it may be possible to add a powerful macro system to Python, while keeping its amazing syntax, and if it could be possible to add Pythonistic syntax to Lisp or Scheme, while keeping all of the...
2
3397
by: Edgar | last post by:
I want to go from viewing a form (record number "x") to the same record ("x") in a report. Of course, when I open the report, it opens to the first record, not record "x". I don't know VBA, only macros. Is there any way to do this with macros (I tried time stamping a field in the form when I enter a record and then using a query to sort by max date as
4
52368
by: Vittal | last post by:
Hello All, Here is a small C program, main() { int a= 100; float b =99.99; TEST(a,%d); TEST(b,%f);
4
1858
by: Max TenEyck Woodbury | last post by:
I need a macro that will take an arbitrarily long list of arguments where each argument needs to be passed to another macro. Is it possible to write such a macro? If so, could you please provide an example?
45
2473
by: madhawi | last post by:
Is it better to use a macro or a function?
3
1886
by: deve8ore | last post by:
Hello, I have built a macro to automatically go to a specific directory and a specific folder, however the names of the files I need to automatically locate change names every month. I.e. - I hit the macro button and I'd like to automatically open a (pdf,xls,doc) file: "C:\Matt\Files\Pricing\Reports\GrossMargin\9279RebateDetail.xls" The only part of the file name that changes every month are the first four numbers before...
2
1590
by: deve8ore | last post by:
Hello, I receive a workbook via 3rd party containing graphs within each sheet. The workbook may contain a different number of sheets per file. I would like to write a macro to go through each sheet in the workbook (except for sheets 1 and 2), and change the name of the series to "Total Membership". Code I've tried to write is as such: Sub Change () Dim ws As Worksheet Workbooks.Open
3
1475
by: thinktwice | last post by:
i want to define a macro like #define STRING2(x) #x #define STRING(x) STRING2(x) #define PROMPT(x) #pragma message(__FILE__ "(" STRING(__LINE__) "):" STRING(x)) <---- compile failed i want to use this macro to remind me that something need to be done but not done yet. is it possible to write such a macro??
13
1506
by: alkos333 | last post by:
I'm trying figure out the best way to deal with the following situations: This scenario is oversimplified for the sake of the question. Let's say I have 3 tables: Transactions, Accounts and Designations. Transactions table has an primary key called Trans_TransId and keeps track of all contact information associated with a transaction. Accounts table contains a list of predefined accounts. It has a primary key called Acc_Code and a...
0
9564
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9387
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10002
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
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
5270
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
5406
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3917
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
3528
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2794
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.