Recursive Definitions: Trouble or Bad news? 
Author Message
 Recursive Definitions: Trouble or Bad news?

I should be interested to know the latest ANSI wisdom on a construct
requesting that token BLUNGE be replaced by itself:
        #define BLUNGE BLUNGE

Intended use is to "remember" that we have done a "typedef" by
defining a preprocessor symbol which has the same name as the type.
--
He cuts half of passenger service | {bpa,uunet}!cdin-1!cdis-1!tanner
Mulroney: "cold froze our brains" | {attctc gatech!uflorida}!ki4pv!cdis-1!tanner



Fri, 19 Mar 1993 14:10:00 GMT  
 Recursive Definitions: Trouble or Bad news?

Quote:
>I should be interested to know the latest ANSI wisdom on a construct
>requesting that token BLUNGE be replaced by itself:
>    #define BLUNGE BLUNGE

ANSI C (draft of last Oct) specifically says that the macro name is not
expanded if encountered within the body of the macro.
--
A bit of tolerance is worth a  |     Henry Spencer at U of Toronto Zoology



Fri, 19 Mar 1993 16:15:00 GMT  
 Recursive Definitions: Trouble or Bad news?

Quote:
>I should be interested to know the latest ANSI wisdom on a construct
>requesting that token BLUNGE be replaced by itself:
>    #define BLUNGE BLUNGE

When BLUNGE is replaced, the attempted recursion is detected and
the macro is left unchanged.  A more complicated example would be

        #define A B
        #define B A
        A

in which A is replaced by B and during the rescan B is replaced by A.
The next rescan detects the recursion, and this A is unreplaced and
is the result.

Yes, this implies that the macro replacement algorithm must keep track
of potentially lots of information.

Dave Prosser    ...not an official X3J11 answer...



Fri, 19 Mar 1993 19:37:00 GMT  
 Recursive Definitions: Trouble or Bad news?

Quote:
>    #define BLUNGE BLUNGE
>Intended use is to "remember" that we have done a "typedef" by
>defining a preprocessor symbol which has the same name as the type.

Why not use a different symbol?  Seems like an unnecessary complication.


Fri, 19 Mar 1993 23:45:00 GMT  
 Recursive Definitions: Trouble or Bad news?

Quote:
>I should be interested to know the latest ANSI wisdom on a construct
>requesting that token BLUNGE be replaced by itself:
>    #define BLUNGE BLUNGE

This works.  ANSI says that nested replacements do not recognize a
macro name which has already been replaced.  It's not so clear with
more complicated examples though.

--

  The above opinions are inherited by your machine's init process (pid 1),
  after being disowned and orphaned.  However, if you see this at Waterloo or
  Anterior, then their administrators must have approved of these opinions.



Fri, 19 Mar 1993 02:33:00 GMT  
 Recursive Definitions: Trouble or Bad news?

writes:

Quote:
>>        #define BLUNGE BLUNGE

>ANSI C (draft of last Oct) specifically says that the macro name is not
>expanded if encountered within the body of the macro.

But is BLUNGE within BLUNGE?

The wine may be within the glass, but is the glass within the glass?


UUCP:  oliveb!cirrusl!dhesi



Fri, 19 Mar 1993 07:29:00 GMT  
 Recursive Definitions: Trouble or Bad news?

Quote:
>I should be interested to know the latest ANSI wisdom on a construct
>requesting that token BLUNGE be replaced by itself:
>    #define BLUNGE BLUNGE

That's allowed, and the replacement string's BLUNGE will not be expanded.
However, note that some pre-ANSI C preprocessors may do this differently.


Fri, 19 Mar 1993 02:46:00 GMT  
 
 [ 7 post ] 

 Relevant Pages 

1. Borland C++ 4.02 (Good News and Bad News)

2. "C-contest: 79 RECURSIVE (extremely bad:-)"

3. Recursive Definition?

4. recursive definition

5. indirect recursive definition

6. typedeffing function pointers and recursive definitions...

7. Recursive function definition

8. choice of news server might have been the trouble

9. news group trouble

10. trouble with recursive trigger

11. NEED DOC: Trouble with RS232 and bauds rate definitions

12. Reply news is listed as separate message in my news reader

 

 
Powered by phpBB® Forum Software