Verify and/or improvement
Verify and/or improvement
Removed by me
Last edited by Rens on Oct 27, 2010 17:47, edited 1 time in total.
Nice work... is *arg being 0 at the end just an incidental quirk or a documented feature? Is it just reaching the (initialized as 0) result value when it hits "0"?
Perhaps the examples should change to two: one where it is logical to pass a count parameter (such as something that returns an array pointer, or maybe something where each value refers to another array value -- ie, where the count is critical), and one where it isn't needed.
Perhaps the examples should change to two: one where it is logical to pass a count parameter (such as something that returns an array pointer, or maybe something where each value refers to another array value -- ie, where the count is critical), and one where it isn't needed.
Null-termination is a common way to mark the end of a var len parameter list. See gtk_show_about_dialog as an example.j_milton wrote:Ren's method requires you to have the last argument you pass when you call the function be a "dummy" with a value of 0
Re: Verify and/or improvement
The problem here is that 0.0 and 0 are both valid numbers which you are going to need to pass at some point in time, and then your whole system fails. The same for negative numbers. For specific cases sentinel numbers may work, but it isn't a general solution. The wiki should have general cases that work for any situation. This would be a good tip in the Community section but no in the general wiki.Rens wrote: Questions is : How many arguments are passed to the function?
Answer: Use a sentinel as a closing marker, for doubles 0.0 and for integers 0
@Rens:
Have a look at this Wiki page and you'll know if your code is OK.
If you like to extent this example, you should consider passing pointers in the parameter list. This way you can pass various types inside the parameter list and you'll get rid of the termination issue. But the compiler cannot do any type checks for this code.
Have a look at this Wiki page and you'll know if your code is OK.
If you like to extent this example, you should consider passing pointers in the parameter list. This way you can pass various types inside the parameter list and you'll get rid of the termination issue. But the compiler cannot do any type checks for this code.