Recursive C Macros

morulis

Member
Mar 5, 2005
89
0
0
Can C support recursive macros? I tried to make factorial with macros not with functions and I did not do it. Any ideas?:)

Thank you in advance
 

itachi

Senior member
Aug 17, 2004
390
0
0
ansi c doesn't support recursive macros.. if your compiler supports it, you'll probably need to find a flag.. if it doesn't, try and find one that does.

why a macro?
 

icelazer

Senior member
Dec 17, 1999
323
0
71
Doubt this is possible, this is referring to C++, but...

5. Macros can't recurse.

We can write a recursive function, but it's impossible to write a recursive macro. As the C++ standard says, in 16.3.4/2:

If the name of the macro being replaced is found during this scan of the replacement list (not including the rest of the source file's pre- processing tokens), it is not replaced. Further, if any nested replacements encounter the name of the macro being replaced, it is not replaced. These nonreplaced macro name preprocessing tokens are no longer available for further replacement even if they are later (re)examined in contexts in which that macro name preprocessing token would otherwise have been replaced.

from: http://www.gotw.ca/gotw/077.htm