473,322 Members | 1,538 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,322 software developers and data experts.

Odd Macro Problem

I have a macro that can be used like:

E(errno);

but for reasons of brevity I frequently use the form:

E(errno = EINVAL);

But I would like to be able to have two definitions such that it evaluates
to an active form like:

printf("%d\n", errno);
OR
printf("%d\n", errno = EINVAL);

and an inactive form that does nothing. The problem is, if I define the
macro as simply:

#ifdef INACTIVATE
#define E(val)
#else
#define E(val) printf("%d\n", (val))
#endif

then the inactive form will not emit the 'errno = EINVAL' expression
and set the value. If I define the inactive macro as:

#define E(val) (val)

that can emit a useless expression like:

errno;

Is there a way to write this macro to solve this problem and still
satisfy all of the other requirements?

Thanks,
Mike
Nov 14 '05 #1
1 1268
Michael B Allen wrote:
I have a macro that can be used like:

E(errno);

but for reasons of brevity I frequently use the form:

E(errno = EINVAL);

But I would like to be able to have two definitions such that it evaluates
to an active form like:

printf("%d\n", errno);
OR
printf("%d\n", errno = EINVAL);

and an inactive form that does nothing. The problem is, if I define the
macro as simply:

#ifdef INACTIVATE
#define E(val)
#else
#define E(val) printf("%d\n", (val))
#endif

then the inactive form will not emit the 'errno = EINVAL' expression
and set the value. If I define the inactive macro as:

#define E(val) (val)

that can emit a useless expression like:

errno;

Is there a way to write this macro to solve this problem and still
satisfy all of the other requirements?


No, because "all the other requirements" leaves too much
to the imagination ... Nonetheless, I'll don my Carnak The
Magnificent turban, dust off the Magic Eight-Ball, oil the
Ouija board, cast the yarrow stalks, burn a chicken feather,
and intone:

YE MAY BE WELL-PLEASED BY ONE FROM YE OLDE LISTE:

#define E(val) (val)
/* "Useless expression," pfui. Damn the torpedoes! */

#define E(val) ((void)(val))
/* Still useless, but perhaps less noisy. */

#define E(val) report_error(val)
/* Let the function decide what to do, if anything. */

AN NONE OF THESE PLEASE YE, ABANDON THY LOVE OF "BREVITY"
AND ESCHEW YON SIDE-EFFECTS IN YR MACRO ARGUMENTS. TREMBLE,
MORTAL, FOR THOU HAST BEEN WARNED!

(Alarums and excursions. Blinding lightning and
cataclysmic thunder. When sight returns, the Oracle has
vanished, leaving behind only a whiff of brimstone and one
small demon buzzing around in hope of finding Cyrano.)

--
Eric Sosman
es*****@acm-dot-org.invalid
Nov 14 '05 #2

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

Similar topics

25
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...
699
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...
1
by: Giganews | last post by:
I have an Access 97 database in which I am running an Excel macro through automation. The macro in Excel is as follows: Worksheets("Sheet1").Protect Password:="****", DrawingObjects:=True,...
8
by: David | last post by:
Hi, I am using header file for driver so Can I define macro to call Kernel function ? What are the generatl rules for defining macro. - David
20
by: Srinivas Mudireddy | last post by:
Hi, I am facing a problem with trying to conditionally compile inside a macro. I have a macro #define SET_VAL(x, y) ((x) = *(y)) But the problem is y can be NULL in which case I want to set...
10
by: Praveen.Kumar.SP | last post by:
Hi Could anyone solve the problem for the code below The Code: #include "stdio.h" #include "iostream.h" void Temp( int a, char* str,...)
6
by: Takeadoe | last post by:
Dear NG, Can someone assist me with writing the little code that is needed to run an update table query each time the database is opened? From what I've been able to glean from this group, the...
8
by: Net | last post by:
Hi Please help. I have a database which requires a message to come up when certain part numbers are added to it. I have solved part of this by using a conditional macro eg = 54125 and using a msg...
6
by: jason | last post by:
Hi, I learned my lesson about passing pointers, but now I have a question about macros. Why does the function work and the MACRO which is doing the same thing on the surface, does not work in...
36
by: sh.vipin | last post by:
how to make large macro paste the code as it is Problem Explanation '-- For example in the program below /* a.c - starts here */ #define DECL_VARS() \ unsigned int a0;\ unsigned int a1;\...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.