Thread: Macros with multiple lines

  1. #1
    Registered User
    Join Date
    Nov 2003
    Posts
    2

    Question Macros with multiple lines

    Hi, I am currently a student in web development and have to do some c programming. I am having trouble with a homework problem and would appreciate any help.

    I have to write a program that defines and uses macro MINIMUM2 to determine the smallest of two numeric values. Input the values from the keyboard.

    What I have so far isn't working, I have the macro defined as:

    <code>
    #define MINIMUM2( x, y ) ( if ( x < y )\
    small = x;\
    else if\
    X > y\
    small = y;\
    else\
    printf( "x and y are equal\n" ); )
    </code>


    I get errors when trying to compile the program. My book says to put \ at the end of a line when the replacement text continues on the next line. But it isn't working.

    thanks for any help

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    Code:
    #define MINIMUM2(x, y) ((x) < (y) ? (x) : (y))
    Then use it like this:
    Code:
    small = MINIMUM2(x, y);
    Unless you're doing something completely different if x and y are equal, this solution is what you want. If you really, really want to use function-like macros that is.
    My best code is written with the delete key.

  3. #3
    Registered User
    Join Date
    Nov 2003
    Posts
    2

    Talking Thank you

    Thanks prelude, that worked alot better than what I had.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Your biggest project: how many lines have you written?
    By happyclown in forum A Brief History of Cprogramming.com
    Replies: 44
    Last Post: 04-29-2009, 07:30 AM
  2. Problem with deleting completely blank lines
    By dnguyen1022 in forum C Programming
    Replies: 3
    Last Post: 12-07-2008, 11:51 AM
  3. why Multiple define error ...
    By nilathinesh in forum C Programming
    Replies: 2
    Last Post: 10-19-2006, 06:31 AM
  4. Replies: 1
    Last Post: 05-01-2003, 02:52 PM
  5. Multiple lines on an Edit box
    By RubenJ in forum Windows Programming
    Replies: 3
    Last Post: 09-20-2001, 02:51 PM