Help answer threads with 0 replies.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 04-24-2010, 01:10 AM   #1
LQ Newbie
Registered: Mar 2009
Posts: 28

Rep: Reputation: 15
what are self-referential macros?

Hi all
Can someone tell me what are self-referential macros in C?Could you give simple example for the same?

Thanks & Regards
Old 04-24-2010, 08:38 AM   #2
Registered: May 2009
Distribution: Debian wheezy
Posts: 252

Rep: Reputation: 31
I have never head that term before, but it sounds like it means a macro that refers to itself, otherwise known as a recursive macro. An example in m4 would be the factorial function:
define(`factorial', `_$0($1, 1)')dnl
define(`_factorial', `ifelse($1, `0', $2, `$0(decr($1), eval($1 `*' $2))')')dnl
Basically, if you give factorial the argument of 0, it returns its internal counter, which defaults to 1. Otherwise it multiplies a counter by your argument, decrements the argument, and calls itself again.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: Better database design with foreign keys and referential integrity ... LXer Syndicated Linux News 0 07-19-2006 10:21 PM
Macros In C drumstick Programming 8 11-21-2005 05:37 PM
Macros Twi7ch Linux - General 2 08-27-2005 10:37 PM
Question about macros Nerox Programming 4 04-03-2005 04:34 AM
Self referential structs in C? MadCactus Programming 14 01-28-2004 06:29 PM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 11:01 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration