Thread: function with variable parameters in C

  1. #1
    Registered User
    Join Date
    Jun 2002
    Posts
    13

    function with variable parameters in C

    How do you declare and call a function with a variable number of parameters in C? I'm assuming that this would be similar to C++ function overloading, but I can't seem to find a complete description. I've seen some mentioning of using ... or > in the declaration, but nothing that really helps. Anyone got any suggestions?

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    A variable number of parameters, or actual overloaded functions?

    a) variable number of parameters:

    void myfunction( int x, ... );
    /* ... means variable parameters */

    b) actual overloaded functions

    void myfun( int x );
    void myfun( float f );

    You cannot have overloading in C.
    You can have variable parameters though, as per the definition of
    printf.

    The thing about variable parameters is that you have to have some way of telling your function what parameters are actually there. This is what printf does with it's % tags in the first format.

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

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. sorting number
    By Leslie in forum C Programming
    Replies: 8
    Last Post: 05-20-2009, 04:23 AM
  2. Need some help...
    By darkconvoy in forum C Programming
    Replies: 32
    Last Post: 04-29-2008, 03:33 PM
  3. error LNK2001: unresolved external symbol
    By Unregistered in forum C Programming
    Replies: 12
    Last Post: 07-12-2002, 08:45 PM
  4. qt help
    By Unregistered in forum Linux Programming
    Replies: 1
    Last Post: 04-20-2002, 09:51 AM
  5. Variable Allocation in a simple operating system
    By awkeller in forum C Programming
    Replies: 1
    Last Post: 12-08-2001, 02:26 PM