View previous topic :: View next topic |
Author |
Message |
Futterama
Joined: 17 Oct 2005 Posts: 98
|
How to make function argument optional? |
Posted: Fri Sep 01, 2006 3:43 am |
|
|
Hello forum,
How do I make a function's argument optional?
And how do I check if an argument was passed when the function was called?
Thanks.
Futterama |
|
|
Ttelmah Guest
|
|
Posted: Fri Sep 01, 2006 4:10 am |
|
|
You can't.
This is one of the features added in V4. You can do various forms of 'bodge round' this, with the normal technique being to pass a pointer to an array arguments.
Best Wishes |
|
|
Futterama
Joined: 17 Oct 2005 Posts: 98
|
|
Posted: Fri Sep 01, 2006 4:20 am |
|
|
Thanks for the reply. |
|
|
Oli Guest
|
|
Posted: Mon May 18, 2009 6:21 am |
|
|
Just an update to this topic - does anybody know how to make an argument optional? (and set a default value if it's not passed?)
Many thanks |
|
|
Ttelmah Guest
|
|
Posted: Mon May 18, 2009 7:48 am |
|
|
With V4, you just use an overload.
So (for example):
Code: |
void function(int8 val) {
//Function code here
}
void function(void) {
function(10);
}
|
If you pass a value, the first function gets called, while if you don't, the second gets called, and this then calls the first, with the value defaulting to '10'.
Overloading, is one part of V4, that has been working surprisingly well.
Best Wishes |
|
|
Oli Guest
|
|
Posted: Mon May 18, 2009 9:25 am |
|
|
Thanks again Ttelmah |
|
|
|