arning: passing argument from incompatible pointer type

Guest #1171916
Rate this post
useful
not useful
I'm getting this error from WinARM:

Warning: passing argument 4 of 'AT91F_TWI_ReadByte' from incompatible
pointer type

with this code:

char read[5];

int AT91F_TWI_ReadByte(const AT91PS_TWI pTwi ,int mode, /
                         int int_address, char * data, int nb)
{
   some code here;
}

void main(void)
{
   AT91F_TWI_ReadByte(AT91C_BASE_TWI, LED_CONTROLLER0, 0x02, &read, 1);
}


What is incompatible with the pointer?


- Joe
Guest #1171917
Rate this post
useful
not useful
1. Mistake in code, no reason to blame WinARM
2. warning != error
3. test with &read[0] or just read and try to understand the difference
to &read
4. use int main(void) to avoid another warning
5. read a C-book (i.e. Brian W. Kernighan and Dennis M. Ritchie, The C
Programming Language) or C-tutorial soon.
#1171918
Rate this post
useful
not useful
&read has type char** not char* you simply need just read on its own
which has type char[] which is compatible with char*, or &read[0] which
is a char*.

A char[] when passed as a function parameter always degrades to char* in
any case.

The only difference between a char* and char[] is the value of sizeof();

char read[10] ;
char* pRead = read ;

sizeof(read) == 10
sizeof(pRead) == 4 (on a 32bit architecture such as ARM)

Clifford
Guest #1171919
Rate this post
useful
not useful
Clifford Slocombe wrote:
> &read has type char** not char* you simply need just read on its own
> which has type char[] which is compatible with char*, or &read[0] which
> is a char*.

Thanks Clifford.  The code is a sample from Atmel, so evidently they
don't know what they are doing either.  (By the way, the IAR compiler
doesn't issue any warnings in it's default setup.)

And Martin, I was in no way blaming WinArm!  I love WinARM!  I
appologise for calling the warning an error.

- Joe

Reply

Please log in before posting.

or

Log in with Google account

Registration is free and takes only a minute.

Register now