Pointer or array?

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

Pointer or array?

1,690件の閲覧回数
roberto_m
Contributor III
In an 8-bit mcu, is better in function arguments use pointer or value?
ラベル(1)
0 件の賞賛
返信
3 返答(返信)

1,121件の閲覧回数
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 件の賞賛
返信

1,121件の閲覧回数
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 件の賞賛
返信

1,121件の閲覧回数
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 件の賞賛
返信