Thread: preprocessor

  1. #1
    Registered User
    Join Date
    Dec 2009
    Posts
    2

    Unhappy preprocessor

    #include<stdio.h>
    #define FUN(arg) do\
    {\
    if(arg)\
    printf("Have fun...","\n");\
    }while(i--)
    void main()
    {
    int i=2;
    FUN(i<3);
    }

    How thit programme giving o/p "Have fun...Have fun...Have fun..."
    can any one help me please.

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Perform the function-style macro expansion yourself and then examine the resulting program.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Dec 2009
    Posts
    2
    hi thanks 4 ur suggestion laserlight ?
    if u know the ans please answer?

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by pin2
    if u know the ans please answer?
    What exactly do you not understand? The use of a function-style macro? The loop itself?
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  5. #5
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    I think you should probably perform the function-style macro expansion yourself and then examine the resulting program.


    Quzah.
    Hope is the first step on the road to disappointment.

  6. #6
    C/Linux Programmer
    Join Date
    Dec 2009
    Posts
    17
    Do you understand how the below program works?
    Code:
    #include<stdio.h>
    void main()
    {
        int i=2;
        do
        {
            if(i<3)
                printf("Have fun...","\n");
        }while(i--);
    }
    Well, that's all what the function-style macro expansion does (colored part)
    Last edited by technam; 12-24-2009 at 12:56 AM. Reason: grammar correction

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. preprocessor problemn
    By indrajit_muk in forum C Programming
    Replies: 2
    Last Post: 04-09-2009, 03:10 AM
  2. Writing an HTML Preprocessor
    By thetinman in forum C++ Programming
    Replies: 1
    Last Post: 09-17-2007, 08:01 AM
  3. Preprocessor Directives Problem
    By MipZhaP in forum C++ Programming
    Replies: 6
    Last Post: 02-18-2005, 01:53 PM
  4. Preprocessor string pasting fun
    By ggambett in forum C Programming
    Replies: 6
    Last Post: 11-11-2004, 06:40 PM
  5. Preprocessor Functions
    By mart_man00 in forum C Programming
    Replies: 2
    Last Post: 01-09-2003, 09:58 PM