[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [MiNT] GCC question



On Wed, 17 Nov 2010 00:07:46 , Vincent Rivière <vincent.riviere@freesbee.fr> wrote:
> Peter Slegg wrote:
> > #define TREE_XYWH(tree) tree[0].ob_x-3,tree[0].ob_y-3,tree[0].ob_width+
> 6,tree[0].ob_height+6
> > objc_draw(dlog, start, MAX_DEPTH, TREE_XYWH(dlog));
> > newsaes.c:651:52: error: macro "objc_draw" requires 7 arguments, but on
> ly 4 given
>
> Let's restart to the beginning.
>
> First, what is objc_draw() ?
> /opt/cross-mint/m68k-atari-mint/include/gem.h:
> #define objc_draw(a,b,c,d,e,f,g) mt_objc_draw(a,b,c,d,e,f,g,aes_global)
>
> So with the GemLib (used by GCC), objc_draw() is a macro taking 7 argumen
> ts.
> If you try to call it with any other number of arguments, it the compilat
> ion
> will quickly fail at preprocessing stage.
> This is what is happening to you, and why you are getting the error.
>
> With Pure C, which use a different GemLib, objc_draw() is probably define
> d
> as a real function. So the expansion of the macro TREE_XYWH() occurs befo
> re
> the call to the function objc_draw(), and it works.
>
> So what is the solution with GCC and the GemLib ?
> Create a new macro with 4 arguments:
> #define objc_draw4(a,b,c,d) objc_draw(a,b,c,d)
>
> Then whenever there is a call to objc_draw() with 4 arguments, use
> objc_draw4() instead:
> objc_draw4(dlog, start, MAX_DEPTH, TREE_XYWH(dlog));
> And this will work.
>
> Finally, this is not a GCC or Pure C issue. This is a GemLib issue. Since
>
> the GemLib functions are implemented as macros, they don't allow to be
> called with macro arguments which expands to several arguments like TREE_
> XYWH().
> Anyway, that kind of macro should be considered as evil.
>

I agree with you but the odd thing is that the gcc -E option correctly
expands all the macros in the preprocessor before compilation. This is
what I would expect a PRE-processor to do. The macros shouldn't get as
far as the compiler.

It is a bit horrible and your fix looks neat.

Regards,

Peter