Pointer or array?

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Pointer or array?

906 Views
roberto_m
Contributor III
In an 8-bit mcu, is better in function arguments use pointer or value?
Labels (1)
0 Kudos
3 Replies

337 Views
bigmac
Specialist III

Hello Roberto,

 

My understanding is that, when a function uses an array name as an argument, the contents of the array are not passed to the function, but a pointer to the first element of the array is automatically passed instead.  Therefore I would suspect that passing an array name, or explicitly passing a pointer should give similar results.

 

Regards,

Mac

 

0 Kudos

337 Views
Lundin
Senior Contributor IV

Correct. There is no way to pass an array by value as a function parameter in the C language.

 

 void func (int* x); /* this is a pointer */

 

void func(int x[]); /* this is a pointer */

 

void func(int x[10]); /* this is a pointer */

 

In all 3 cases above, a pointer is passed on the stack, and nothing else.

0 Kudos

337 Views
kef
Specialist I

Pointer of course. Passing array by value you rise stack space requirements. Also passing array by value slows down execution, because it takes time to copy array from source to the stack.

0 Kudos