2

I have this function

unsigned char NCN_System_upload(unsigned char *data, unsigned char len);

I have an array defined as such:

unsigned char data[3];

I'm using the function as the following:

NCN_System_upload(&data, 3);

However, I get the following error:

argument of type unsigned char (*)[3] is incompatible with parameter of type unsigned char*

Why doesn't this work?

1
  • 1
    Arrays naturally decays to pointers, so no need for the address-of operator. Commented Aug 22, 2015 at 13:59

1 Answer 1

3

The name of the array is already (can be implicitly converted) to a pointer to its beginning. Thus, you should do it like this:

NCN_System_upload(data, 3);
Sign up to request clarification or add additional context in comments.

3 Comments

I knew I was being super dumb. Thanks!
The official wording would be the name of the array already decays to a pointer.... Arrays do not always act the same as pointers.
Actually, "decays" is an informal description as well (albeit one a lot of people seem to use). The description in the standard - bearing in mind that the purpose of the standard is to be the definitive specification - is that "An lvalue or rvalue of type “array of N T” or “array of unknown bound of T” can be converted to an rvalue of type “pointer to T.” The result is a pointer to the first element of the array." This is a long-winded way of describing an implicit conversion. The word "decay" (or variants) does not even appear in the standards.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.