Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.compilers > #390

Re: macros, was Looking for volunteers for XL

From Kaz Kylheku <kaz@kylheku.com>
Newsgroups comp.compilers
Subject Re: macros, was Looking for volunteers for XL
Date 2011-12-13 01:39 +0000
Organization A noiseless patient Spider
Message-ID <11-12-018@comp.compilers> (permalink)
References <11-11-048@comp.compilers> <11-11-061@comp.compilers> <11-11-064@comp.compilers> <11-12-002@comp.compilers> <11-12-017@comp.compilers>

Show all headers | View raw


On 2011-12-13, Joe keane <jgk@panix.com> wrote:
> #2. Don't use function-like macros.
>
> Make the result one of the parameters (unless it is really simple, then
> some day in the future your 'really simple' macro is not so really
> simple).
>
> e.g.
>
>     #define GET_FORDO_BIT(FOP) \
>     ...
>
>     int f(int x)
>     {
> 	...
> 	if (GETFORDO_BIT(fop))
> 	{
> 	    ...
> 	}
> 	...
>     }
>
> versus
>
>     #define GET_FORDO_BIT(FOP, FOB) \
>     ...
>
>     int f(int x)
>     {
> 	...
> 	GET_FORDO_BIT(fop, fob);
> 	if (fob)
> 	{
> 	    ...
> 	}
> 	...
>     }
>
> How hard is that?

It's not hard to make, just hard to use.

Problem is, you're creating something akin to an assembly language,
with instructions that have source and destination operands.

GET_FORDO_BIT(FOP, FOB) cannot be used as a subexpression in a larger
expression.

If you have any complex computation going on made up of macros of this
type, you have to declare lots of temporary variables, and lay these
instructions in sequence, like a machine language program.

Now you need a compiler to generate that cruft for you.

The need for generating temporary variables has not gone away.
We've just given up doing it in the macro and shifted it onto the
programmer, who would rather now shift it back onto the machine.

Sure, if these macros are few and far between, that may be acceptable. In that
situation, you have nice code, whose structure is just broken up here and there
with an ugly imperative macro like this.  It's intractable if you have many of
them, and want to write programs that are mostly made up of those macros.

Real macros let you do that: make robust languages that make heavy, dense use
of those macros, not only some syntactic sugar that is to be sprinkled very
sparingly.
[Seems to me that what you really want here is in-line functions.  Macros are
useful for other stuff, too. -John]

Back to comp.compilers | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

Looking for volunteers for XL Christophe de Dinechin <christophe@taodyne.com> - 2011-11-22 21:03 -0800
  Re: Looking for volunteers for XL Kaz Kylheku <kaz@kylheku.com> - 2011-11-26 05:43 +0000
  Re: Looking for volunteers for XL Christophe de Dinechin <christophe@taodyne.com> - 2011-11-26 12:38 -0800
    Re: Looking for volunteers for XL "BartC" <bc@freeuk.com> - 2011-11-26 23:19 +0000
      Re: Looking for volunteers for XL Christophe de Dinechin <christophe@taodyne.com> - 2011-11-27 12:34 -0800
        Re: Looking for volunteers for XL "BartC" <bc@freeuk.com> - 2011-11-27 22:24 +0000
          Re: Looking for volunteers for XL Christophe de Dinechin <christophe@taodyne.com> - 2011-11-28 14:12 -0800
            Re: Looking for volunteers for XL ardjussi <jussi.santti@ard.fi> - 2011-11-30 13:16 -0800
              Re: Looking for volunteers for XL Kaz Kylheku <kaz@kylheku.com> - 2011-12-01 05:44 +0000
                Re: overloading, was Looking for volunteers for XL glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2011-12-02 05:36 +0000
          Re: Looking for volunteers for XL tm <thomas.mertes@gmx.at> - 2012-01-03 09:28 -0800
      Re: Looking for volunteers for XL Kaz Kylheku <kaz@kylheku.com> - 2011-11-28 04:45 +0000
        Re: Looking for volunteers for XL Timothy Knox <tdk@thelbane.com> - 2011-11-27 22:50 -0800
          Re: Looking for volunteers for XL Alex McDonald <blog@rivadpm.com> - 2011-12-01 12:11 -0800
        Re: Looking for volunteers for XL "BartC" <bc@freeuk.com> - 2011-11-28 10:23 +0000
          Re: Looking for volunteers for XL glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2011-11-29 07:37 +0000
            Re: macros, Looking for volunteers for XL Gene Wirchenko <genew@ocis.net> - 2011-12-03 17:36 -0800
              Re: macros, Looking for volunteers for XL glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2011-12-05 04:24 +0000
          Re: Looking for volunteers for XL Kaz Kylheku <kaz@kylheku.com> - 2011-12-01 05:35 +0000
            Re: designing language extensions, was Looking for volunteers for XL Marco van de Voort <marcov@toad.stack.nl> - 2011-12-03 13:02 +0000
            Re: Looking for volunteers for XL jgk@panix.com (Joe keane) - 2011-12-13 00:08 +0000
              Re: macros, was Looking for volunteers for XL Kaz Kylheku <kaz@kylheku.com> - 2011-12-13 01:39 +0000
                Re: macros, was Looking for volunteers for XL Kaz Kylheku <kaz@kylheku.com> - 2011-12-14 19:00 +0000
                Re: macros, was Looking for volunteers for XL jgk@panix.com (Joe keane) - 2011-12-15 15:40 +0000
                Re: macros, was Looking for volunteers for XL Kaz Kylheku <kaz@kylheku.com> - 2011-12-16 17:48 +0000
        Re: Looking for volunteers for XL glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2011-11-28 10:26 +0000

csiph-web