K
kid joe
Hello all
Long time no posting! I've mostly been using Java these couple years, but
now I'm working on a C project again. The group seems a lot quieter than
it used to be and lots of familiar names no longer appear in the recent
post lists - quite a change!
Anyway, 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?
--
( )
( )
G O O D ( ) M O R N I N G ! !
( )
) )
( ( /\
(_) / \ /\
________[_]________ /\/ \/ \
/\ /\ ______ \ / /\/\ /\/\
/ \ //_\ \ /\ \ /\/\/ \/ \
/\ / /\/\ //___\ \__/ \ \/
/ \ /\/ \//_____\ \ |[]| \
/\/\/\/ //_______\ \|__| \
/ \ /XXXXXXXXXX\ \
\ /_I_II I__I_\__________________\
I_I| I__I_____[]_|_[]_____I
I_II I__I_____[]_|_[]_____I
I II__I I XXXXXXX I
~~~~~" "~~~~~~~~~~~~~~~~~~~~~~~~
Long time no posting! I've mostly been using Java these couple years, but
now I'm working on a C project again. The group seems a lot quieter than
it used to be and lots of familiar names no longer appear in the recent
post lists - quite a change!
Anyway, 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?
--
( )
( )
G O O D ( ) M O R N I N G ! !
( )
) )
( ( /\
(_) / \ /\
________[_]________ /\/ \/ \
/\ /\ ______ \ / /\/\ /\/\
/ \ //_\ \ /\ \ /\/\/ \/ \
/\ / /\/\ //___\ \__/ \ \/
/ \ /\/ \//_____\ \ |[]| \
/\/\/\/ //_______\ \|__| \
/ \ /XXXXXXXXXX\ \
\ /_I_II I__I_\__________________\
I_I| I__I_____[]_|_[]_____I
I_II I__I_____[]_|_[]_____I
I II__I I XXXXXXX I
~~~~~" "~~~~~~~~~~~~~~~~~~~~~~~~