... parameter

Hiho all! I was wondering how does the ... work in the printf function. Is it just an unlimited amount of parameters of any type? Can i implement it in my own functions? Thanks!
Take a look at the va_ set of macros, they allow you to do this kind of thing.

http://www.cplusplus.com/reference/clibrary/cstdarg/va_list/
closed account (z05DSL3A)
A bit of code...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include <iostream>
#include <cassert>
#include <cstdarg>
using namespace std;


int max(unsigned count, ...)
{
    assert(count > 0);
   
    va_list arguments;
    
    va_start(arguments, count);

    int result = va_arg(arguments, int);
    
    while(--count > 0)
    {
        int arg = va_arg(arguments, int);
        if (arg > result)
            result = arg;
    }
    
    va_end(arguments);

    return result;
}


int main() 
{
    int a(56), b(8), c(66),d(14);
    cout << max(4 /*number of parameters passed */, a, b, c, d) <<endl;
    
    return 0;
}
Thanks for help! I got the idea.
Topic archived. No new replies allowed.