simple macro not working???

This is a discussion on simple macro not working??? within the C++ Programming forums, part of the General Programming Boards category; Can anybody tell me why this won't compile. I am trying to understand who macro's work and this seems about ...

  1. #1
    Registered User
    Join Date
    Jul 2003
    Posts
    26

    simple macro not working???

    Can anybody tell me why this won't compile. I am trying to understand who macro's work and this seems about as simple as it gets.

    Code:
     #include <iostream>
     
    using std::cout;
    using std::cin;
    using std::endl;
    
    #define MINIMUM2 (x,y)    if (x < y)            \          
                                lowestNumber = x;   \
                              else                  \
                                lowestNumber = y;
                            
    #define NUM1 = 5
    #define NUM2 = 10
    
    
    //***************************************************
    //MAIN FUNCTION
    int main()
    {
       
       double lowestNumber = 0;
                   
       MINIMUM2(NUM1, NUM2);
    
       cout << "Lowest number = " << lowestNumber;
      
       return 0;
    }

  2. #2
    pronounced 'fib' FillYourBrain's Avatar
    Join Date
    Aug 2002
    Posts
    2,297
    space in the macro definition before the parameters. This looks strangely familiar.
    "You are stupid! You are stupid! Oh, and don't forget, you are STUPID!" - Dexter

  3. #3
    Registered User
    Join Date
    Jul 2003
    Posts
    26
    I removed that space and also remove the "=" signs form the sysbolic constant for NUM1 and NUM2.

    The error are getting fewer but there is still something wrong with the macro defination. Here is one of the errors I am still getting:

    error C2501: 'lowestNumber' : missing storage-class or type specifiers

    Any ideas??

  4. #4
    pronounced 'fib' FillYourBrain's Avatar
    Join Date
    Aug 2002
    Posts
    2,297
    Code:
    #include <iostream>
     
    using namespace std;
    
    #define MINIMUM2(x,y)((x<y)?x:y)
                            
    #define NUM1  5
    #define NUM2  10
    
    
    // **************************************************
    
    
    //MAIN FUNCTION
    int main()
    {
       
       double lowestNumber = MINIMUM2(NUM1, NUM2);
    
       cout << "Lowest number = " << lowestNumber;
      
       return 0;
    }
    fixed
    "You are stupid! You are stupid! Oh, and don't forget, you are STUPID!" - Dexter

  5. #5
    Registered User
    Join Date
    Jul 2003
    Posts
    26
    Thanks, That worked, but I don't understand it.

    What didn't the compiler like about the way I had it?

    What does ?x:y do in the macro?

    Thanks,

  6. #6
    'AlHamdulillah
    Join Date
    Feb 2003
    Posts
    790
    What does ?x:y do in the macro?
    its true or false, "?"means true. ":" means false

  7. #7
    pronounced 'fib' FillYourBrain's Avatar
    Join Date
    Aug 2002
    Posts
    2,297
    but there were other errors I should point out. Here's your original code with the big things I changed in red
    Code:
    #include <iostream>
     
    using std::cout;
    using std::cin;
    using std::endl;
    
    #define MINIMUM2 (x,y)    if (x < y)            \          
                                lowestNumber = x;   \
                              else                  \
                                lowestNumber = y;
                            
    #define NUM1 = 5
    #define NUM2 = 10
    
    
    // **************************************************
    *
    //MAIN FUNCTION
    int main()
    {
       
       double lowestNumber = 0;
                   
       MINIMUM2(NUM1, NUM2);
    
       cout << "Lowest number = " << lowestNumber;
      
       return 0;
    }
    "You are stupid! You are stupid! Oh, and don't forget, you are STUPID!" - Dexter

  8. #8
    Registered User
    Join Date
    Jul 2003
    Posts
    26
    So the code checks to see if x < y. If that is true then x is returned if it is false then y is returned.

    Is that correct?

  9. #9
    pronounced 'fib' FillYourBrain's Avatar
    Join Date
    Aug 2002
    Posts
    2,297
    correct.
    "You are stupid! You are stupid! Oh, and don't forget, you are STUPID!" - Dexter

  10. #10
    Registered User
    Join Date
    Jul 2003
    Posts
    26
    Thanks!!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. ifdef is harmful - but simple workaround is not working
    By amitbern in forum C Programming
    Replies: 15
    Last Post: 12-06-2008, 07:02 AM
  2. Replies: 10
    Last Post: 09-08-2008, 12:38 AM
  3. Simple program not working
    By oobootsy1 in forum C# Programming
    Replies: 1
    Last Post: 08-10-2005, 03:20 AM
  4. Replies: 5
    Last Post: 02-02-2003, 10:56 AM
  5. simple program not working
    By Unregistered in forum Windows Programming
    Replies: 2
    Last Post: 03-04-2002, 11:36 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21