Bill Allombert on Fri, 16 Jun 2006 16:48:31 +0200


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

Re: do {...} while(0) macros


On Wed, Jun 14, 2006 at 05:50:37PM +0200, Karim Belabas wrote:
> Hi all,
> 
>   in order to emulate templates in ANSI C, some of the pari code uses the
> (standard, ugly) macro construct:
> 
>   #define foo  do { A; B; } while (0)

> This is especially annoying for the (deprecated) addsiz functions which
> one might conceivably find in code such as
> 
>     GEN i;
>     for ( i = N0; cmpii(i, N) < 0; addsiz(i, 1, i) )
> 
> ( Which is inefficient and should be written differently, as all code
> using the <fun>z functions, but this is beside the point. )
> 
> 
> The simplest "solution" seems to generate most of paricom.h automatically
> from a template [ see the "OPERATION BY VALUE" part ].

How this would fix this problem ? Unless you mean replacing the
macros by functions calls (whic is an option).

> A seemingly better solution is to kill all (obsolete, inefficient,
> difficult to use) <fun>z functions in pari-2.5.

Well having a set of function with GMP-style interface and reasonable
speed would be useful. Unfortunately <fun>z are usually terribly slow
and the semantic is not always what we would expect.

> An intermediate solution would be to simply document the problem (say as
> a FAQ item) and forget about it.

In my opinion, we _have to_ document the list of function that are
actually macros, because macros always behave differently than functions
(e.g you cannot dlopen() them). On the other hand, the way we implement
macros is perfectly standard and should not cause surprise once they are 
documented as macros.

Cheers,
Bill.