I get the warning:
expected 'const CHAR *' but argument is of type 'CHAR (*)[18]'
Why is the compiler giving me this warning? This is the line I am using to call to the api:
AG_AS(g_AgMgrCtx.audio_device.Profile_Type,&g_AgMgrCtx.SDevAddr);
The declaration of the function is
AG_AS(AG_DType d_type , CHAR *addr);
char SDevAddr[18];
What is the problem with passing the address? When I remove &
the warning goes away.
What does the warning actually mean?
That means your call should be (without the &
):
AG_AS(g_AgMgrCtx.audio_device.Profile_Type, g_AgMgrCtx.SDevAddr);
g_AgMgrCtx.SDevAddr
is an array of 18 chars. So when you pass it to a function, it gets converted into a pointer to its first element (thus matching the type that AG_AS()
expects).
Relevant: What is array decaying?
When you have an object like this
T obj;
where T is some type then expression &obj
has type T *
that is it is a pointer to an object of type T
.
This array declaration
char SDevAddr[18];
can be transformed to the form shown above using a typedef. For example
typedef char T[18];
T SDevAddr;
In this case expression &SDevAddr
has type T *
as it has been pointed above. however in this case T
in turn an alias for the type char[18]
. Thus &SDevAddr
is a pointer to an object of type char[18]
Its type looks like char ( * )[18]
.
However as it is seen from the function declaration
AG_AS(AG_DType d_type , CHAR *addr);
the second parameter has type char *
. If you will pass as an argument the array itself like SDevAddr
then it will be implicitly converted to pointer to its first element and will have type char *
that is required for the function call.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.