Thread: small prob

  1. #1
    Registered User newbie_grg's Avatar
    Join Date
    Jul 2002

    small prob

    ineed to know what is wrong with this macro definition

    #define fac(a) (a)*fac((a)-1)
    "If knowledge can create problems, it is not through ignorance that we can solve them. "
    -Isaac Asimov(1920-1992)

  2. #2
    Me want cookie! Monster's Avatar
    Join Date
    Dec 2001
    You cannot put recursion in a define. What the compiler does is run through the complete code and replace all defines.

    So fac(10) is replaced by: (10)*fac((10)-1)

    Remember that this is compiletime, not runtime, so the compiler does nothing with the value 10.

    After this you will get a link error because the fac function cannot be found.

  3. #3
    Registered User
    Join Date
    Jan 2002
    Using macros in C++ is far from perfect. I reckon you should consider using inline functions.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. got prob with this small program
    By Hugo716 in forum C++ Programming
    Replies: 4
    Last Post: 05-28-2006, 08:46 PM
  2. want to make this small program...
    By psycho88 in forum C++ Programming
    Replies: 8
    Last Post: 11-30-2005, 02:05 AM
  3. Small array of strings prob
    By bstringer in forum C Programming
    Replies: 15
    Last Post: 08-04-2005, 06:27 PM
  4. FILES in WinAPI
    By Garfield in forum Windows Programming
    Replies: 46
    Last Post: 10-02-2003, 06:51 PM
  5. yhatzee, small straight
    By uglyjack in forum C++ Programming
    Replies: 2
    Last Post: 06-13-2002, 03:09 AM