Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c.moderated > #493 > unrolled thread
| Started by | GilNajera <gilnajera@gmail.com> |
|---|---|
| First post | 2011-02-09 12:22 -0600 |
| Last post | 2011-02-10 21:41 -0600 |
| Articles | 3 — 3 participants |
Back to article view | Back to comp.lang.c.moderated
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: How to declare a function parameter to be optional? GilNajera <gilnajera@gmail.com> - 2011-02-09 12:22 -0600
Re: How to declare a function parameter to be optional? Jens <jens.gustedt@gmail.com> - 2011-02-10 21:40 -0600
Re: How to declare a function parameter to be optional? David RF <davranfor@gmail.com> - 2011-02-10 21:41 -0600
| From | GilNajera <gilnajera@gmail.com> |
|---|---|
| Date | 2011-02-09 12:22 -0600 |
| Subject | Re: How to declare a function parameter to be optional? |
| Message-ID | <clcm-20110209-0002@plethora.net> |
Hi! On 7 feb, 22:58, Pushkar Prasad <pushkar.pra...@live.com> wrote: > Hello All > > Is there a way to ensure that one of the function argument is set as > optional. So that it is not mandatory for the caller to pass that > parameter and yet if necessary can be used? You must set a default value to that parameter when declaring the function: void myFunction(int parameter1, int optional_parameter=23); All non optional parameters must precede the optional ones. So, when you call myFunction using just one parameter, the second will take the value of 23. Hope this helps. -- comp.lang.c.moderated - moderation address: clcm@plethora.net -- you must have an appropriate newsgroups line in your header for your mail to be seen, or the newsgroup name in square brackets in the subject line. Sorry.
[toc] | [next] | [standalone]
| From | Jens <jens.gustedt@gmail.com> |
|---|---|
| Date | 2011-02-10 21:40 -0600 |
| Message-ID | <clcm-20110210-0002@plethora.net> |
| In reply to | #493 |
On 9 Feb., 19:22, GilNajera <gilnaj...@gmail.com> wrote: > You must set a default value to that parameter when declaring the > function: > > void myFunction(int parameter1, int optional_parameter=23); what you describe is valid C++ but not C. for a form to do such a thing in C, please see my answer. Jens -- comp.lang.c.moderated - moderation address: clcm@plethora.net -- you must have an appropriate newsgroups line in your header for your mail to be seen, or the newsgroup name in square brackets in the subject line. Sorry.
[toc] | [prev] | [next] | [standalone]
| From | David RF <davranfor@gmail.com> |
|---|---|
| Date | 2011-02-10 21:41 -0600 |
| Message-ID | <clcm-20110210-0003@plethora.net> |
| In reply to | #493 |
On 9 feb, 19:22, GilNajera <gilnaj...@gmail.com> wrote: > Hi! > > On 7 feb, 22:58, Pushkar Prasad <pushkar.pra...@live.com> wrote: > > > Hello All > > > Is there a way to ensure that one of the function argument is set as > > optional. So that it is not mandatory for the caller to pass that > > parameter and yet if necessary can be used? > > You must set a default value to that parameter when declaring the > function: > > void myFunction(int parameter1, int optional_parameter=23); > > All non optional parameters must precede the optional ones. > > So, when you call myFunction using just one parameter, the second will > take the value of 23. > > Hope this helps. > -- > comp.lang.c.moderated - moderation address: c...@plethora.net -- you must > have an appropriate newsgroups line in your header for your mail to be seen, > or the newsgroup name in square brackets in the subject line. Sorry. void myFunction(int parameter1, int optional_parameter=23); expected ‘;’, ‘,’ or ‘)’ before ‘=’ token You're probably talking about c++ -- comp.lang.c.moderated - moderation address: clcm@plethora.net -- you must have an appropriate newsgroups line in your header for your mail to be seen, or the newsgroup name in square brackets in the subject line. Sorry.
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.c.moderated
csiph-web