Page 1 of 1
C Macros
Posted: Fri Sep 03, 2004 2:52 pm
by Neo
Is there anyway of passing a variable number of arguments to a C macro (#define)
Re:C Macros
Posted: Sat Sep 04, 2004 5:36 am
by Adek336
sure there is. And it's quite useful, as well
Code: Select all
#define printf(...) kprintf(active_console, __VA_ARGS__);
HTH,
~Adrian
Re:C Macros
Posted: Sat Sep 04, 2004 11:30 am
by Neo
Thanks where did you find that?
And another question...
What is the difference between the "#if !defined" and the "#ifndef" preprocessor directives? (if any).
Re:C Macros
Posted: Sat Sep 04, 2004 12:44 pm
by Adek336
Thanks where did you find that?
I self needed them once for some printf+panic variations. Then I found the gcc pre-processor manual in the net.
What is the difference between the "#if !defined" and the "#ifndef" preprocessor directives? (if any).
Well um I've never seen a "#if !defined", but knowing that
#if my_program_version > 300
works well and works as expected,
#if !defined
is probably as much as
#if defined != 0
Cheers
Re:C Macros
Posted: Sat Sep 04, 2004 2:07 pm
by zloba
#if !defined
is probably as much as
#if defined != 0
nope. defined() is a preprocessor test for the argument being defined.
#if !defined(X)
is the same as
#ifndef X
but defined() is an expression which you can combine with other conditions, such as
#if (defined(X) && !defined(Y)) || Z>0
obviously when you are only interested in one thing being defined or not, it's easier to say:
#ifdef X // #if defined(X)
or
#ifndef X // #if !defined(X)