delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2000/10/19/05:12:25

Date: Thu, 19 Oct 2000 11:37:02 +0200 (CEST)
From: Dieter Demerre <ext DOT dieter DOT demerre AT siemens DOT be>
X-Sender: dd AT baby DOT siemens DOT ebp DOT ii3 DOT b-rail DOT be
To: djgpp AT delorie DOT com
Subject: Re: Preprocessor # ##
In-Reply-To: <39ED93DC.6C3ACD2F@ma.tum.de>
Message-ID: <Pine.LNX.4.10.10010190932320.978-100000@baby.siemens.ebp.ii3.b-rail.be>
MIME-Version: 1.0
Reply-To: djgpp AT delorie DOT com
Errors-To: nobody AT delorie DOT com
X-Mailing-List: djgpp AT delorie DOT com
X-Unsubscribes-To: listserv AT delorie DOT com

On Wed, 18 Oct 2000, Waldemar Schultz wrote:

> silly question, but I don't manage to fix it.
> given
> 
> long double sinlong(long double);
> #define sinr(x) sinlong(x)
> #define ACTUAL_NAME(s) ...???...
>                        ^^^^^^^^^^ fill in please
> printf("sinr(x)=%s\n",ACTUAL_NAME(sinr(x));
> should print:
> sinr(x)=sinlong(x)

"...
When a macro has been defined in the second form(*), subsequent textual
...
During collection, arguments are not macro-expanded.
...
In both kinds of macro, the replacement token sequence is repeatedly
rescanned for more defined identifiers.  However, once a given identifier
has been replaced in a given expansion, it is not replaced if it turns up
again during rescanning; instead it is left unchanged.
... " 

(*) #define identifier ( identifier-list ) token-sequence

I fear above is applicable.  I did NOT check with djgpp but did with
gpp(linux) and cc(HP-UX).  They did not agree on what to output.
# ## s resulted 

on linux:gcc -E
`#' operator is not followed by a macro argument name
longsin ( x )

on HP-UX:cc -E -Aa
cpp: error 4010: The '#' operator must precede a parameter.
cpp: error 4008: Cannot have '##' at beginning of replacement string.
longsin(x)

and again
define ACTUAL(s) ### s
turned up on HP-UX:cc -E -Aa as
error 4008: Cannot have '##' at beginning of replacement string 
  printf("sinr(x) == %s\n", "sinr(x)" );

while on Linux:gcc -E reports
`##' at start of macro definition
but also produces
  printf("sinr(x) == %s\n","sinr(x)" );

But then again I guess you tried all those and other combinations... So I
guess it won't do...  Like someone said somewhere for some reason:
"...it's powerfull, but not omnipotent..."

> Thanks for any pointer. (I read a thread about # and ## long ago, but
> I can't find it)

What I consulted:
K&R pp 229-231 A12.3 Macro Definition and Expansion

sorry for not being able to help.  I *am* interested in hearing from a
possible sollution to your problem.

but then again HP-UX cpp obviously does NOT recognise the ##-action.

******* Groetjes vanwege ***** Greetings From *******
Dieter Demerre - http://www.angelfire.com/de/ddemerre
  ddemerre AT acm DOT org - ext DOT dieter DOT demerre AT siemens DOT be

Although this private and confidential e-mail has been sent 
to you through a personal Siemens account, it does NOT 
represent any official opinion of Siemens.

If you are not the intended recipient of this e-mail and 
have received it in error, please notify the sender by 
replying with 'received in error' as the subject and then 
delete it from your mailbox.

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019