Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

expression must have integral type

Tags:

c

pointers

I get that compilation error because of this line which intended to increase the pointer by 0x200 (to point to the next segment)

Flash_ptr = Flash_ptr + (unsigned char *) 0x200;

I'v seen this but I didn't use any illegal symbol!

P.S. The initialization of the pointer:

unsigned char * Flash_ptr = (unsigned char *) 0x20000; 
like image 881
Omayer Gharra Avatar asked Sep 10 '14 09:09

Omayer Gharra


1 Answers

You can't add two pointers. You can add an integer to a pointer, and you can subtract two pointers to get an integer difference, but adding two pointers makes no sense. To solve your problem therefore you just need to remove the cast:

Flash_ptr = Flash_ptr + 0x200;

This increments Flash_ptr by 0x200 elements, but since Flash_ptr is of type unsigned char * then this just translates to an increment of 0x200 bytes.

In order to make this part of a loop and check for an upper bound you would do something like this:

while (Flash_ptr < (unsigned char *)0x50000) // loop until Flash_ptr >= 0x50000
{
    // ... do something with Flash_ptr ...
    Flash_ptr += 0x200;
}
like image 72
Paul R Avatar answered Sep 22 '22 08:09

Paul R