Yes, it has been asked before, many times, but I wanna know which one is more advisable?
typedef struct {
int a;
int addr[8];
} usr_command;
usr_command* p_usr_command;
int foo(int* parameter)
{}
So which one is less prone to be problematic?
foo(p_usr_command->addr);
or
foo(&p_usr_command->addr[0]);
?
In this case ( passing an array name vs. passing the address of the first object in the array as function argument), both the snippets are equivalent.
Quoting
C11
, chapter §6.3.2.1, Lvalues, arrays, and function designators (emphasis mine)However, in general, they are not the same.
array
is an array of typeint [8]
&(array[0])
is a pointer, typeint *
As already suggested by EOF in his comment, try passing both variants to the
sizeof
operator and check the result to get the hands-on output.