FatFs errors in IAR

Go To Last Post
2 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I am working on Chan's FatFs for porting to XMEGA family. There are 2 errors when compiled by IAR:

FRESULT f_write (
	FIL *fp,			/* Pointer to the file object */
	const void* buff,	/* Pointer to the data to be written */
	UINT btw,			/* Number of bytes to write */
	UINT *bw			/* Pointer to number of bytes written */
)
{
	FRESULT res;
	DWORD clst, sect;
	UINT wcnt, cc;
	const BYTE *wbuff = buff;
DRESULT disk_ioctl (
	BYTE drv,		/* Physical drive nmuber (0) */
	BYTE ctrl,		/* Control code */
	void *buff		/* Buffer to send/receive control data */
)
{
	DRESULT res;
	BYTE n, csd[16], *ptr = buff;

Errors are in these lines:

const BYTE *wbuff = buff;
BYTE n, csd[16], *ptr = buff;

Generated errors are:

Error[Pe144]: a value of type "void const *" cannot be used to initialize an entity of type "BYTE const *" 
Error[Pe144]: a value of type "void *" cannot be used to initialize an entity of type "BYTE *"

By these changes, there is no error:

const BYTE *wbuff = (BYTE*)buff;
BYTE n, csd[16], *ptr = (BYTE*)buff;

The question is why IAR (and not AVR GCC) generates these errors and is the change(typecasting) correct?

Ozhan KD
Knowledge is POWER

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You can assign to a void* variable with a BYTE* but you cannot assign to a BYTE* with anything other than another BYTE*.

Your casts are correct.

avr-gcc and most GCCs are often tolerant of this kind of initialisation. Presumably to stop people complaining that it breaks code.

Note that void* is very handy for generic functions like memcpy(). You do not need to use untidy casts on the arguments.

David.