[comp.lang.c] Many lines from a macro?

cspw@quagga.ru.ac.za (Peter Wentworth) (01/23/91)

Can a C macro replacement ever result in more than one output line from
the preprocessing stage?

I am using the SUN assembler which first uses the C preprocessor.
The C macro

#define FOO       jmp label;\
                  nop;\
              label:

expands to this output:       jmp label;  nop;  label:

But the assembler insists that the label starts on a new line,
so this is not acceptable.  Is there some magic that will 
yield three separate lines of macro output, instead of one?

I don't think this can ever cause problems in C, but I suspect
there other languages that would benefit from using a general
standardized C preprocessor as a front end.  Was there ever any
notion among the ANSI committee that things like preprocessing
features could be included on grounds of 'general usefulness',
rather than 'useful only to C'?

Pete 

-- 
EP Wentworth - Dept. of Computer Science - Rhodes University - Grahamstown.
cspw@quagga.ru.ac.za  
  (If that fails, try cspw.quagga@f4.n494.z5.fidonet.org)

gwyn@smoke.brl.mil (Doug Gwyn) (01/24/91)

In article <1991Jan22.201702.1383@quagga.ru.ac.za> cspw@quagga.ru.ac.za (Peter Wentworth) writes:
>Is there some magic that will yield three separate lines of
>macro output, instead of one?

No.

>I don't think this can ever cause problems in C, but I suspect
>there other languages that would benefit from using a general
>standardized C preprocessor as a front end.  Was there ever any
>notion among the ANSI committee that things like preprocessing
>features could be included on grounds of 'general usefulness',
>rather than 'useful only to C'?

No, in fact there is no requirement that the result of the
preprocessing phases of translation be made externally available
at all.  This permits tightly integrated C implementations that
compile appreciably faster than implementations that produce
an accessible preprocessed source text along the way.

As has been pointed out numerous times, there are general-purpose
macro preprocessors available, which you should use for any
application other than as part of the C phases of translation.

diamond@jit345.swstokyo.dec.com (Norman Diamond) (01/24/91)

In article <1991Jan22.201702.1383@quagga.ru.ac.za> cspw@quagga.ru.ac.za (Peter Wentworth) writes:

>Can a C macro replacement ever result in more than one output line from
>the preprocessing stage?

In obscure cases, it is possible, depending on the implementation.
But not in any reliable or useful manner.
(The imaginable case is where the macro call has arguments on more than
one line.)

>I am using the SUN assembler which first uses the C preprocessor.

Cute.  But as you've observed, not especially useful.

>The C macro
>#define FOO       jmp label;\
>                  nop;\
>              label:
>expands to this output:       jmp label;  nop;  label:

There is no real choice in this matter.  The backslash-newline pairs are
deleted before the preprocessor even sees the macro definition.

>But the assembler insists that the label starts on a new line,

>I don't think this can ever cause problems in C,

Of course not.

>but I suspect
>there other languages that would benefit from using a general
>standardized C preprocessor as a front end.

There is a relatively portable preprocessor called M4.  It is cute that
no one wants to use M4 to preprocess C programs, but some people want to
use the C preprocessor to preprocess programs for other languages.

>Was there ever any
>notion among the ANSI committee that things like preprocessing
>features could be included on grounds of 'general usefulness',
>rather than 'useful only to C'?

When the ANSI C committee standardized C, even "useful to C" was not
always a criterion.  Often only "prior art" or "base document" were
criteria.  In cases were "useful" was the primary criterion, some of
the results are unpopular.

Other ANSI committees standardize other languages (and other industries
besides the computer business).  If you want to standardize a macro
processor, get a bunch of computer companies together and apply to
form another ANSI committee.
--
Norman Diamond       diamond@tkov50.enet.dec.com
If this were the company's opinion, I wouldn't be allowed to post it.