On Tue, 9 Jan 2001, Eric Pouech wrote:

> > > well, I just had in mind to test for macros defined as
> > > #define macro()
> > 
> >    But the above is absolutely valid C code.
> > 
> > > and replace it by #define macro (void)
> > 
> >    This too is valid C code. It's a macro that takes exactly one
> > argument called void.
> nope... 

   Well, actually you're right.

> #define macro (void)
> is a macro defined without arguments. So

   But here you're wrong. The above is a macro which takes less than 0
argument. It does not even take the parentheses! It's just the most
basic kind of macro, it's called 'macro', it's value is '(void)' andyou
invoke it every time you write 'macro' (not 'macro()').
   That's because there is a space between 'macro' and '(void)'. Here's
a test case:

--- cut here ---
#define DPF()
#define foo          (void)+1     
#define foo0()       (void)+1
#define foo1(void)   (void)+1

void func()
{
    int a;

    foo;
    foo0();
    foo1(a);
    DPF();
}
--- cut here ---

Now preprocess the above and you'll get (gcc 2.95):

--- cut here ---
$ gcc -E macro.c
# 1 "macro.c"





void func()
{
    int a;

    (void)+1 ;
    (void)+1 ;
    ( a )+1 ;
     ;
}
--- cut here ---

   As you see 'foo' takes no parameter, not even '()' while 'foo1' does
take one parameter. You can also compile it and it compiles just fine.
You will only get a warning 'statement with not effect' for '( a )+1 ;'
which makes perfect sense. Finally, as you can see 'DPF()' compiles just
fine with gcc (and any other C compiler).
   One last thing: check out the definition of 'Yield32' in winbase.h.
It's the exact equivalent of DPF, isn't it?

#define     Yield32()


--
Francois Gouget         [EMAIL PROTECTED]        http://fgouget.free.fr/
                      Computers are like airconditioners
                They stop working properly if you open WINDOWS




Reply via email to