Array arguments always by reference?

If you have a simple question and just want an answer.
DemoniacMilk
XCore Addict
Posts: 191
Joined: Tue Jul 05, 2016 2:19 pm

Array arguments always by reference?

Post by DemoniacMilk »

Code: Select all

[...]
rx_client_state_t rx_client_state_lp[n_rx_lp];
init_rx_client_state(rx_client_state_lp, n_rx_lp);
[...]

void init_rx_client_state(rx_client_state_t client_state[n], unsigned n)
{
  for (int i = 0; i < n; i ++) {
    client_state[i].dropped_pkt_cnt = 0;
    client_state[i].rd_index = 0;
[...]
Are array arguments always passed by reference? Are they copied to the stack, then copied back on return or does the compiler change them to a pointer?

Ou nevermind, i found the answer in this topic
peter
XCore Addict
Posts: 230
Joined: Wed Mar 10, 2010 12:46 pm

Post by peter »

Thanks for finding your own answer :-)

I might also be worth pointing out that when using interfaces it gives the compiler the ability perform optimisation and only send the data that has to be sent. So, in the example given here:

https://www.xmos.com/published/how-pass ... face-calls

the compiler can know that the client only uses two elements of the entire array and only send those two elements. This is particularly useful when passing arrays between different tiles where the data has to be copied and can't be accessed through shared memory.