Verify and/or improvement

General FreeBASIC programming questions.
Post Reply
Rens
Posts: 256
Joined: Jul 06, 2005 21:09

Verify and/or improvement

Post by Rens »

Removed by me
Last edited by Rens on Oct 27, 2010 17:47, edited 1 time in total.
agamemnus
Posts: 1842
Joined: Jun 02, 2005 4:48

Post by agamemnus »

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.
j_milton
Posts: 458
Joined: Feb 11, 2010 17:35

Post by j_milton »

agamemnus wrote: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"?
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
TJF
Posts: 3809
Joined: Dec 06, 2009 22:27
Location: N47°, E15°
Contact:

Post by TJF »

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
Null-termination is a common way to mark the end of a var len parameter list. See gtk_show_about_dialog as an example.
agamemnus
Posts: 1842
Joined: Jun 02, 2005 4:48

Post by agamemnus »

*facepalm*

I didn't see that..
Rens
Posts: 256
Joined: Jul 06, 2005 21:09

Post by Rens »

Removed by me
Last edited by Rens on Oct 27, 2010 17:46, edited 1 time in total.
rdc
Posts: 1741
Joined: May 27, 2005 17:22
Location: Texas, USA
Contact:

Re: Verify and/or improvement

Post by rdc »

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
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
Posts: 256
Joined: Jul 06, 2005 21:09

Post by Rens »

rdc,

You are absolutely right.

Maybe i find another solution, but until then, do not use these functions!
Use the function from the wiki.

Thanks for verifying.
TJF
Posts: 3809
Joined: Dec 06, 2009 22:27
Location: N47°, E15°
Contact:

Post by TJF »

@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.
Post Reply