Click here to Skip to main content
15,916,683 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Passing an array as argument to a function Pin
Greg Utas30-Mar-20 2:40
professionalGreg Utas30-Mar-20 2:40 
GeneralRe: Passing an array as argument to a function Pin
Richard MacCutchan30-Mar-20 3:28
mveRichard MacCutchan30-Mar-20 3:28 
GeneralRe: Passing an array as argument to a function Pin
Greg Utas30-Mar-20 3:35
professionalGreg Utas30-Mar-20 3:35 
GeneralRe: Passing an array as argument to a function Pin
Richard MacCutchan30-Mar-20 4:04
mveRichard MacCutchan30-Mar-20 4:04 
GeneralRe: Passing an array as argument to a function Pin
Greg Utas30-Mar-20 4:11
professionalGreg Utas30-Mar-20 4:11 
GeneralRe: Passing an array as argument to a function Pin
Richard MacCutchan30-Mar-20 4:24
mveRichard MacCutchan30-Mar-20 4:24 
GeneralRe: Passing an array as argument to a function Pin
k505430-Mar-20 4:58
mvek505430-Mar-20 4:58 
GeneralRe: Passing an array as argument to a function Pin
k505429-Mar-20 7:52
mvek505429-Mar-20 7:52 
GeneralRe: Passing an array as argument to a function Pin
Calin Negru29-Mar-20 8:11
Calin Negru29-Mar-20 8:11 
GeneralRe: Passing an array as argument to a function Pin
k505429-Mar-20 9:42
mvek505429-Mar-20 9:42 
GeneralRe: Passing an array as argument to a function Pin
Calin Negru30-Mar-20 22:30
Calin Negru30-Mar-20 22:30 
GeneralRe: Passing an array as argument to a function Pin
Calin Negru31-Mar-20 21:36
Calin Negru31-Mar-20 21:36 
GeneralRe: Passing an array as argument to a function Pin
Richard MacCutchan31-Mar-20 23:02
mveRichard MacCutchan31-Mar-20 23:02 
GeneralRe: Passing an array as argument to a function Pin
Calin Negru31-Mar-20 23:26
Calin Negru31-Mar-20 23:26 
GeneralRe: Passing an array as argument to a function Pin
Richard MacCutchan1-Apr-20 0:36
mveRichard MacCutchan1-Apr-20 0:36 
GeneralRe: Passing an array as argument to a function Pin
Calin Negru1-Apr-20 1:12
Calin Negru1-Apr-20 1:12 
GeneralRe: Passing an array as argument to a function Pin
Richard MacCutchan1-Apr-20 1:26
mveRichard MacCutchan1-Apr-20 1:26 
GeneralRe: Passing an array as argument to a function Pin
Calin Negru1-Apr-20 1:49
Calin Negru1-Apr-20 1:49 
GeneralRe: Passing an array as argument to a function Pin
Richard MacCutchan1-Apr-20 2:45
mveRichard MacCutchan1-Apr-20 2:45 
GeneralRe: Passing an array as argument to a function Pin
Calin Negru1-Apr-20 5:19
Calin Negru1-Apr-20 5:19 
GeneralRe: Passing an array as argument to a function Pin
Richard MacCutchan1-Apr-20 6:39
mveRichard MacCutchan1-Apr-20 6:39 
GeneralRe: Passing an array as argument to a function Pin
Calin Negru31-Mar-20 4:42
Calin Negru31-Mar-20 4:42 
GeneralRe: Passing an array as argument to a function Pin
Richard MacCutchan31-Mar-20 4:58
mveRichard MacCutchan31-Mar-20 4:58 
GeneralRe: Passing an array as argument to a function Pin
Calin Negru31-Mar-20 5:28
Calin Negru31-Mar-20 5:28 
AnswerRe: Passing an array as argument to a function Pin
Stefan_Lang30-Mar-20 23:18
Stefan_Lang30-Mar-20 23:18 
You can do either of these, depending on what you want to do:
C++
// pass read only array of ints
void process_Carray(int const* values, int n_values);
template <int size> // caution: this will create a separate function for each array size!
void process_C11array(std::array<int,size> const& values);
void process_vector(std::vector<int> const& values);
// pass read/write array of ints
void process_Carray(int* values, int n_values);
template <int size> // caution: this will create a separate function for each array size!
void process_C11array(std::array<int,size>& values);
void process_vector(std::vector<int>& values);

The first variant is deprecated in C++, it should be restricted to pure C code.
The second variant is useful if you know the size of your arrays at compile time (and it's always the same)
The third variant is the most flexible as you don't need to know the array size, and you can even add more values within your function if you desire.
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)

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.