View previous topic :: View next topic |
Author |
Message |
nickdc
Joined: 19 Sep 2018 Posts: 15
|
Casting void pointer: a numeric expression must appear here |
Posted: Sat Nov 17, 2018 6:53 am |
|
|
I use a PIC18F47K42 and the CCS compiler v5.081. I'm in the process of porting the following code from XC8 to CCS.
https://www.studentcompanion.co.za/interfacing-sd-card-with-pic-microcontroller-xc8/
I get an error in the function 'validate', which I'm unable to resolve:
Code: |
static
FRESULT validate ( /* FR_OK(0): The object is valid, !=0: Invalid */
void* obj /* Pointer to the object FIL/DIR to check validity */
)
{
FIL *fil;
fil = (FIL *) obj; /* Assuming offset of .fs and .id in the FIL/DIR structure is identical */
...
} |
The error message on the casting line "A numeric expression must appear here."
So I'm casting a void pointer to a FIL* pointer.
FIL is declared as follows:
Code: |
typedef struct {
FATFS* fs; /* Pointer to the related file system object (**do not change order**) */
WORD id; /* Owner file system mount ID (**do not change order**) */
blabla flag; /* Status flags */
blabla err; /* Abort flag (error code) */
DWORD fptr; /* File read/write pointer (Zeroed on file open) */
DWORD fsize; /* File size */
DWORD sclust; /* File start cluster (0:no cluster chain, always 0 when fsize is 0) */
DWORD clust; /* Current cluster of fpter (not valid when fprt is 0) */
DWORD dsect; /* Sector number appearing in buf[] (0:invalid) */
#if !_FS_READONLY
DWORD dir_sect; /* Sector number containing the directory entry */
blabla* dir_ptr; /* Pointer to the directory entry in the win[] */
#endif
#if _USE_FASTSEEK
DWORD* cltbl; /* Pointer to the cluster link map table (Nulled on file open) */
#endif
#if _FS_LOCK
UINT lockid; /* File lock ID origin from 1 (index of file semaphore table Files[]) */
#endif
#if !_FS_TINY
blabla buf[_MAX_SS]; /* File private data read/write window */
#endif
} FIL;
|
Where is my mistake? |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sat Nov 17, 2018 10:58 am |
|
|
nickdc wrote: |
"a numeric expression must appear here"
Where is my mistake?
|
I get the error on this line:
Quote: | static FRESULT validate |
Reason: You don't have FRESULT defined. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun Nov 18, 2018 2:39 pm |
|
|
There is another reason.
You have two variables with the same name FIL and fil. This is not good.
CCS is not case sensitive by default. To fix this, add #case near the top
of your program. Example:
Quote: |
#include <18F46K22.h>
#fuses INTRC_IO, NOWDT
#use delay(clock=4M)
#use rs232(UART1, baud=9600, ERRORS)
#case
void main()
{
|
|
|
|
nickdc
Joined: 19 Sep 2018 Posts: 15
|
|
Posted: Mon Nov 19, 2018 12:03 pm |
|
|
Thanks. The #case was indeed the cause of the problem. |
|
|
|