CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

How to make function argument optional?

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Futterama



Joined: 17 Oct 2005
Posts: 98

View user's profile Send private message

How to make function argument optional?
PostPosted: Fri Sep 01, 2006 3:43 am     Reply with quote

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







PostPosted: Fri Sep 01, 2006 4:10 am     Reply with quote

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

View user's profile Send private message

PostPosted: Fri Sep 01, 2006 4:20 am     Reply with quote

Thanks for the reply.
Oli
Guest







PostPosted: Mon May 18, 2009 6:21 am     Reply with quote

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







PostPosted: Mon May 18, 2009 7:48 am     Reply with quote

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







PostPosted: Mon May 18, 2009 9:25 am     Reply with quote

Thanks again Ttelmah
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group