Thread: non static number of function parameters?

  1. #1
    Registered User
    Join Date
    Aug 2001
    Posts
    411

    non static number of function parameters?

    Ive seen some library functions that do it, but lets say...


    How would you write a max() function that could take 2 or more parameters, without rewriting the function for 3 params, 4 params, 5 params, etc..?

  2. #2
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    Code:
    int max (int num_para, ... ) {
    // Stuff to do the compares for each item
    return the_value_of_the_max_item;
    }
    look up va_list for more on how to handle variable number of parameters

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem with Free.
    By chakra in forum C Programming
    Replies: 9
    Last Post: 12-15-2008, 11:20 AM
  2. Replies: 28
    Last Post: 07-16-2006, 11:35 PM
  3. [GLUT] Pointers to class methods
    By cboard_member in forum C++ Programming
    Replies: 13
    Last Post: 02-16-2006, 04:03 PM
  4. Tab Controls - API
    By -KEN- in forum Windows Programming
    Replies: 7
    Last Post: 06-02-2002, 09:44 AM
  5. I need help with passing pointers in function calls
    By vien_mti in forum C Programming
    Replies: 3
    Last Post: 04-24-2002, 10:00 AM