• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Recursive C Macros

morulis

Member
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
 
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?
 
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
 
Back
Top