[comp.sources.d] ANSI C preproccessor concatenate

drw@cullvax.UUCP (Dale Worley) (08/11/87)

allbery@ncoast.UUCP (Brandon S. Allbery) writes:
- The reason for this is that I have a cpp macro which provides function proto-
- types under ANSI C and omits them for old-fashioned C.  Example:
- 
- 	DEFUN(extern generic malloc, (unsigned));
- 
- becomes
- 
- 	extern generic malloc(unsigned);

[Under ANSI C he writes:]

- #define DEFUN(fn,proto)		fn##proto
- 
- It assumes that X3J11 is #defined by ANSI C (wrong, I'm certain) and that the
- concatenation operator is ## (I think this is right).  (Purists would argue
- that ## isn't needed; but I have a thing about "xx (yy)" as a function defi-
- nition; I want to search for functions with "xx(" and C control structures
- (if, while, switch) with "xx (".)

You'll lose big if you try this!  The reason is that the ## operator
concatenates the character representation of the two surrounding
tokens to form what must be the character representation of a token.
Calling DEFUN(func,(a,b)) tries to concatenate the two tokens "func"
and "(", which together don't form a token.

Dale
-- 
Dale Worley	Cullinet Software		ARPA: cullvax!drw@eddie.mit.edu
UUCP: ...!seismo!harvard!mit-eddie!cullvax!drw
OS/2: Yesterday's software tomorrow	    Nuclear war?  There goes my career!

allbery@ncoast.UUCP (08/16/87)

As quoted from <1449@cullvax.UUCP> by drw@cullvax.UUCP (Dale Worley):
+---------------
| allbery@ncoast.UUCP (Brandon S. Allbery) writes:
| [Under ANSI C he writes:]
| 
| - #define DEFUN(fn,proto)		fn##proto
| 
| You'll lose big if you try this!  The reason is that the ## operator
| concatenates the character representation of the two surrounding
| tokens to form what must be the character representation of a token.
| Calling DEFUN(func,(a,b)) tries to concatenate the two tokens "func"
| and "(", which together don't form a token.
+---------------

Ack, Phphhftht!!!  Any votes for sanity?  Orthogonality?  (No, we vote for
supporting TRSDOS 1.2)-;
-- 
 Brandon S. Allbery, moderator of comp.sources.misc and comp.binaries.ibm.pc
  {{harvard,mit-eddie}!necntc,well!hoptoad,sun!mandrill!hal}!ncoast!allbery
ARPA: necntc!ncoast!allbery@harvard.harvard.edu  Fido: 157/502  MCI: BALLBERY
   <<ncoast Public Access UNIX: +1 216 781 6201 24hrs. 300/1200/2400 baud>>
** Site "cwruecmp" is changing its name to "mandrill".  Please re-address **
*** all mail to ncoast to pass through "mandrill" instead of "cwruecmp". ***