Thread: Functions of arbitrary parameters

  1. #1
    Registered User
    Join Date
    Aug 2008
    Posts
    55

    Functions of arbitrary parameters

    While browsing a c++ faq I came across this comparison with C and found something I either didn't know or am reading wrong.
    Code:
    [6.11] Is C++ backward compatible with ANSI/ISO C?
    
    Almost.
    
    C++ is as close as possible to compatible with C, but no closer. In practice, the major difference is that C++ requires prototypes, and that f() declares a function that takes no parameters (in C, a function declared using f() can be passed an arbitrary number of parameters of arbitrary types).
    Is this saying that defining a function as something like

    Code:
    void f(); 
    
    /*...*/
    
    void f(){
    /*...*/
    }
    would let one do something like

    Code:
    f(45, 100);
    or

    Code:
    f("string", NUM, 2);
    or whatever? If so how do you refer to each argument in the function?

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    You are thinking of variable argument lists, but here that FAQ is talking about the number and types of parameters being unspecified in the declaration (but they may be specified in the definition).
    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
    Aug 2008
    Posts
    55
    Oh I see. Thanks

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Functions &passing parameters by reference
    By Labmouse in forum C++ Programming
    Replies: 6
    Last Post: 12-08-2007, 09:29 AM
  2. Inline functions and inheritance
    By hpy_gilmore8 in forum C++ Programming
    Replies: 3
    Last Post: 01-14-2004, 06:46 PM
  3. Passing pointers between functions
    By heygirls_uk in forum C Programming
    Replies: 5
    Last Post: 01-09-2004, 06:58 PM
  4. pointers, functions, parameters
    By sballew in forum C Programming
    Replies: 3
    Last Post: 11-11-2001, 10:33 PM