No bug here. The warning says it all: the size of void
is zero. gptr++ advances the pointer by 1*sizeof(void)
which is still zero.
If you think you can be smart and use parentheses to
tell the compiler it's a char*, forget it, you can't
either. A cast value is no so-called lvalue and as such
cannot have anything assigned to it nor can it be
incremented.
What you need is a properly typed copy of the pointer.
char *charptr = (char *)gptr;
*charptr++ = 'A';
> Hi, All!
> Here is a little chunk of code.
>
> /* --------------- */
> void some_func(void * gptr) {
> *((char *)gptr++) = 'A';
> }
> /* --------------- */
>
> [EMAIL PROTECTED] sdcc-ptr++]$ uname -o
> GNU/Linux
> [EMAIL PROTECTED] sdcc-ptr++]$ sdcc -mmcs51 -c --std-sdcc99 sdcc-ptr++-test.c
> sdcc-ptr++-test.c:2: warning 178: size of void is zero
> [EMAIL PROTECTED] sdcc-ptr++]$ c99 -c sdcc-ptr++-test.c
> [EMAIL PROTECTED] sdcc-ptr++]$
>
> It's looks like a bug, because gcc compiles it well. Code is not generated
> for increment:
> ;------------------------------------------------------------
> ;Allocation info for local variables in function 'some_proc'
> ;------------------------------------------------------------
> ;gptr Allocated to registers r2 r3 r4
> ;------------------------------------------------------------
> ;sdcc-ptr++-test.c:1: void some_proc(void * gptr) {
> ; -----------------------------------------
> ; function some_proc
> ; -----------------------------------------
> _some_proc:
> ar2 = 0x02
> ar3 = 0x03
> ar4 = 0x04
> ar5 = 0x05
> ar6 = 0x06
> ar7 = 0x07
> ar0 = 0x00
> ar1 = 0x01
> ; genReceive
> ;sdcc-ptr++-test.c:2: *((char *)gptr++) = 'A';
> ; genPointerSet
> ; genGenPointerSet
> mov r2,dpl
> mov r3,dph
> mov r4,b
> ; Peephole 238.d removed 3 redundant moves
> mov a,#0x41
> ; Peephole 253.b replaced lcall/ret with ljmp
> ljmp __gptrput
> .area CSEG (CODE)
> .area XINIT (CODE)
>
> Thank you!
>
> -------------------------------------------------------------------------
> Take Surveys. Earn Cash. Influence the Future of IT
> Join SourceForge.net's Techsay panel and you'll get the chance to share your
> opinions on IT & business topics through brief surveys - and earn cash
> http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
> _______________________________________________
> Sdcc-user mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/sdcc-user
>
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Sdcc-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/sdcc-user