[comp.sys.apollo] Internal cpp in /usr/lib/cc != /usr/lib/cpp

casey@CS.UCLA.EDU (08/23/88)

  The following define extracted from MH 6.5 doesn't work with cc's internal
C preprocessor, but does with /usr/lib/cpp:

	#define	grot(x)	case 'x': *dp++ = '\x'; break;

With /usr/lib/cpp, grot(n) expands to:

	case 'n': *dp++ = '\n'; break;

but cc's internal preprocessor produces:

	case 'n': *dp++ = '\x'; break;

Casey

wesommer@ATHENA.MIT.EDU (Bill Sommerfeld) (08/24/88)

MH6.5 is in error.

The `Reiser' cpp (/usr/lib/cpp or /lib/cpp) happens to expand macros
and macro arguments inside quoted strings, but this is not something
which can be depended upon.

The draft proposed ANSI C standard, which is (partially) implemented
by /com/cc, specifies that the preprocessor should NOT expand macros
or macro arguments inside quoted strings.  If you look at other ANSI
compilers (GNU CC is a good example), you will find the same behavior,
although there may be some way to revert to the old, broken
"reiserisms".

To have source which will work with all C compilers, change the macro
to:

	#define grot(x) case x: *dp++ = x; break;

and all invocations of it to:
	grot('n')

			Bill Sommerfeld
			Apollo Computer/MIT Project Athena

casey@admin.cognet.ucla.edu (Casey Leedom) (08/25/88)

In article <8808240139.AA02024@OLIVER.MIT.EDU> wesommer@ATHENA.MIT.EDU (Bill Sommerfeld) writes:
| 
| The `Reiser' cpp (/usr/lib/cpp or /lib/cpp) happens to expand macros and
| macro arguments inside quoted strings, but this is not something which
| can be depended upon.  The draft proposed ANSI C standard, which is
| (partially) implemented by /com/cc, specifies that the preprocessor
| should NOT expand macros or macro arguments inside quoted strings.
| 
| To have source which will work with all C compilers, change the macro
| to:
| 
| 	#define grot(x) case x: *dp++ = x; break;
| 
| and all invocations of it to:
| 
| 	grot('n')

  Thanks for your note Bill.  Your solution is wrong however.  There is in
fact no way to implement the MH macro in the preprocessor you describe.
Yet another step backwards for an already underpowered macro processor.

Casey

wesommer@ATHENA.MIT.EDU (Bill Sommerfeld) (08/25/88)

   Thanks for your note Bill.  Your solution is wrong however.  

Huh?  It works.. I even tested it with SR10 /com/cc.  What do you mean
by "wrong"?

   There is in
   fact no way to implement the MH macro in the preprocessor you describe.
   Yet another step backwards for an already underpowered macro processor.

If you don't like the fact that you can't wrap a macro argument with
'', complain to ANSI X3J11, don't complain to apollo.  X3J11 isn't
likely to do anything about it, though.

				- Bill