Click here to Skip to main content
15,891,184 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Another academic question - ANSI C standard on optional function parameters Pin
CPallini1-Sep-14 9:39
mveCPallini1-Sep-14 9:39 
GeneralRe: Another academic question - ANSI C standard on optional function parameters Pin
Richard MacCutchan1-Sep-14 21:23
mveRichard MacCutchan1-Sep-14 21:23 
GeneralRe: Another academic question - ANSI C standard on optional function parameters Pin
Vaclav_2-Sep-14 8:11
Vaclav_2-Sep-14 8:11 
GeneralRe: Another academic question - ANSI C standard on optional function parameters Pin
Richard MacCutchan2-Sep-14 20:31
mveRichard MacCutchan2-Sep-14 20:31 
GeneralRe: Another academic question - ANSI C standard on optional function parameters Pin
Vaclav_6-Sep-14 5:59
Vaclav_6-Sep-14 5:59 
GeneralRe: Another academic question - ANSI C standard on optional function parameters Pin
Richard MacCutchan6-Sep-14 6:10
mveRichard MacCutchan6-Sep-14 6:10 
GeneralRe: Another academic question - ANSI C standard on optional function parameters Pin
Stefan_Lang2-Sep-14 21:11
Stefan_Lang2-Sep-14 21:11 
AnswerRe: Another academic question - ANSI C standard on optional function parameters Pin
Stefan_Lang2-Sep-14 0:52
Stefan_Lang2-Sep-14 0:52 
Since C doesn't allow overloading to start with, the only way to call a function with alternate sets of parameters is by thinking up a pattern on how you pass these parameters in a less rigid way.

One way has already been mentioned: passing an array of void pointers. The disadvantage is that you have to figure out what is what, including type, and if more than one parameter is optional you need to additionally pass some information about which of the parameters were skipped.

Pretty much the same goes for vararg lists.

A slightly better approach that offers strict control over types and meaning of parameters is passing a struct that contains all possible parameters: write one function that allocates and/or initializes the struct with defaults, and in the code overwrite all values that you want different, then pass the struct to your processing function. If you have mandatory parameters without sensible defaults (e. g. array sizes), make sure to pass these to the intialization function.
GOTOs are a bit like wire coat hangers: they tend to breed in the darkness, such that where there once were few, eventually there are many, and the program's architecture collapses beneath them. (Fran Poretto)

QuestionHow to Resolve the Below Error? Pin
Sunil931-Aug-14 5:37
Sunil931-Aug-14 5:37 
AnswerRe: How to Resolve the Below Error? Pin
«_Superman_»31-Aug-14 6:04
professional«_Superman_»31-Aug-14 6:04 
GeneralRe: How to Resolve the Below Error? Pin
Sunil931-Aug-14 18:23
Sunil931-Aug-14 18:23 
Questionhow to print the value of variable which is define in header file.? Pin
mybm129-Aug-14 21:14
mybm129-Aug-14 21:14 
AnswerRe: how to print the value of variable which is define in header file.? Pin
Richard MacCutchan29-Aug-14 22:57
mveRichard MacCutchan29-Aug-14 22:57 
GeneralRe: how to print the value of variable which is define in header file.? Pin
mybm129-Aug-14 23:06
mybm129-Aug-14 23:06 
GeneralRe: how to print the value of variable which is define in header file.? Pin
Richard MacCutchan29-Aug-14 23:44
mveRichard MacCutchan29-Aug-14 23:44 
GeneralRe: how to print the value of variable which is define in header file.? Pin
mybm129-Aug-14 23:59
mybm129-Aug-14 23:59 
AnswerRe: how to print the value of variable which is define in header file.? Pin
Richard MacCutchan30-Aug-14 0:48
mveRichard MacCutchan30-Aug-14 0:48 
GeneralRe: how to print the value of variable which is define in header file.? Pin
mybm130-Aug-14 19:09
mybm130-Aug-14 19:09 
AnswerRe: how to print the value of variable which is define in header file.? Pin
Stefan_Lang2-Sep-14 2:36
Stefan_Lang2-Sep-14 2:36 
QuestionDisplaying the output of another program Pin
oldbritthumper29-Aug-14 4:49
oldbritthumper29-Aug-14 4:49 
QuestionRe: Displaying the output of another program Pin
Richard MacCutchan29-Aug-14 5:37
mveRichard MacCutchan29-Aug-14 5:37 
AnswerMessage Closed Pin
29-Aug-14 5:59
oldbritthumper29-Aug-14 5:59 
GeneralRe: Displaying the output of another program Pin
Richard MacCutchan29-Aug-14 6:05
mveRichard MacCutchan29-Aug-14 6:05 
Questionbattleship game code using c language Pin
Member 1104199227-Aug-14 20:37
Member 1104199227-Aug-14 20:37 
AnswerRe: battleship game code using c language Pin
Richard MacCutchan27-Aug-14 22:15
mveRichard MacCutchan27-Aug-14 22:15 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.