arning: passing argument from incompatible pointer type

Guest #1171916
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
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
&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
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

A question of your own? This thread is over 20 years old. Ask it in a thread of its own – more people read along there, and it gets answered more often and sooner.

Start a new thread

A fix, an addition or feedback on this thread? Then reply here.

Formatting
  • [c]C-Code[/c]
  • [code]code in other languages, ASCII drawings[/code]
  • [math]formula (LaTeX syntax)[/math]
  • [[Title]] – link to an article
  • Link to another post: right-click its post ID (#8078628), copy the address, paste it into the text

More about formatting

Post long source code as an attachment, not in the text.

Already registered? Log in

Not shown to anyone. We send you a link; your post appears once you confirm it there.

By submitting you create a free account and accept the terms of use.