Question regarding pointers.

What is the difference between

vw_send((uint8_t *)&msg, strlen(&msg));
vw_wait_tx();

AND

vw_send((uint8_t *)msg, strlen(msg));
vw_wait_tx();
It is difficult to say what is the difference because type of msg is not known in each code snip. For example in the second code snip msg can be a pointer while in the first code snip msg is not a pointer. For example let assume that msg has type of char in the first code snip and in the second code snip it has type of char *. In this case the both code do the same: they pass a pointer to uint8 as the first argument and the length of a pointer to char as the second argument..
Fundamentally, the difference between "variable_name" and "&variable_name" (except in a function declaration's parameter list, where it means something a little different) is that "variable_name" means "I want the value that this variable is currently set to", while "&variable_name" means "I want the address at which this variable is stored" (in other words, gives you an on-the-fly pointer to the named variable).
Topic archived. No new replies allowed.