Following code is not compiled correctly and causes never ending loop. GCC 4.0.2 from GNUARM.org distribution was used.
typedef unsigned short U16; void * ptr = buffer; void * end = (U16 *)buffer + num; while (ptr != end) { *((U16 *&)ptr)++ = c; } dissasebly with intermixed source code: void * ptr = buffer; void * end = (U16 *)buffer + num; 924: e2812a02 add r2, r1, #8192 ; 0x2000 while (ptr != end) 928: e1520001 cmp r2, r1 92c: e50b1038 str r1, [fp, #-56] 930: 0a000250 beq 948 <_ZN7MvbcLSA8InitChipEhh+0x228> 934: e3a00000 mov r0, #0 ; 0x0 938: e1a03001 mov r3, r1 { *((U16 *&)ptr)++ = c; 93c: e0c300b2 strh r0, [r3], #2 940: 1a00024d bne 93c <_ZN7MvbcLSA8InitChipEhh+0x21c> 944: e50b3038 str r3, [fp, #-56] } arm-elf-gcc --ver Using built-in specs. Target: arm-elf Configured with: ../gcc-4.0.2/configure --target=arm-elf --prefix=/g/gnuarm-4.0.2 --enable-interwork --enable-multilib --with-newlib --with-headers=../newlib-1.14.0/newlib/libc/include --enable-languages=c,c++ Thread model: single gcc version 4.0.2 -- Summary: while and (type *&)variable++ causes never ending loop Product: gcc Version: 4.0.2 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: kalas at unicontrols dot cz GCC host triplet: cygwin GCC target triplet: arm-elf http://gcc.gnu.org/bugzilla/show_bug.cgi?id=27306