I read the RFE 905167 and wrote a short senseless
program, it results in detecting a bug:
sdcc -v
SDCC : mcs51/ds390/pic16/TININative/xa51/ds400 2.4.7
#897
int *intptr;
void *voidptr;
char main (void)
{
int x[2] = {0,4711};
char res;
voidptr = x;
intptr = x;
/*
< voidptr++; // No warning, but o.k. since sizeof(void)
== 0
*/
voidptr += sizeof(int); // but here it's *NOT*
incremented, too
intptr++;
res = (*(int *)voidptr == *intptr); // should be true
return(res);
}
All files (test.c, test.asm, ...) as an windows zip archive
Logged In: YES
user_id=888171
This is no bug. If you agree voidptr++ doesn't increment is
ok, than you should know that voidptr+=sizeof(int) doesn't
increment either. Sizeof(int) only returns a number, just like
++ means +=1. In this case 1 is the number. This number
must be multiplied by the size of the object the pointer points
to. In this case 0.
If you want to use sizeof() to increment the pointer to the
next object, it must be added to a char* casted version:
voidptr = (char*)voidptr + sizeof(int);
Hope this clarifies things