C Macros

Programming, for all ages and all languages.
Post Reply
User avatar
Neo
Member
Member
Posts: 842
Joined: Wed Oct 18, 2006 9:01 am

C Macros

Post by Neo »

Is there anyway of passing a variable number of arguments to a C macro (#define)
Only Human
Adek336

Re:C Macros

Post by Adek336 »

sure there is. And it's quite useful, as well :)

Code: Select all

#define printf(...)  kprintf(active_console, __VA_ARGS__);
HTH,
~Adrian
User avatar
Neo
Member
Member
Posts: 842
Joined: Wed Oct 18, 2006 9:01 am

Re:C Macros

Post 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).
Only Human
Adek336

Re:C Macros

Post 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 ;)
zloba

Re:C Macros

Post 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)
Post Reply