From: SourceForge.net <no...@so...> - 2003-04-08 21:16:23
|
Bugs item #604575, was opened at 2002-09-04 12:22 Message generated for change (Comment added) made by felmasper You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=100599&aid=604575&group_id=599 Category: C-Front End Group: fixed Status: Open Resolution: Fixed Priority: 5 Submitted By: Felipe Massia Pereira (felmasper) Assigned to: Johan Knol (johanknol) Summary: ptr ++ with cast and derref Initial Comment: GCC compiles this in ANSI mode. ~/test $ cat ptr++.c #include <stdio.h> char x[4] = { 1, 2, 3, 4 }; int acc, i; int *p; void main() { acc = 0; p = (int *) x; for (i=0; i<2; i++) acc += *((int *)p)++; printf("%d\n",acc); } ~/test $ sdcc -mz80 ptr++.c ptr++.c:13: error: 'lvalue' required for '++' operation . ptr++.c:15: error: code not generated for 'main' due to previous errors ---------------------------------------------------------------------- >Comment By: Felipe Massia Pereira (felmasper) Date: 2003-04-08 18:32 Message: Logged In: YES user_id=387191 I compiled without -pedantic option. (gcc -ansi test.c) This code snippet is, in fact, an IP checksum calculation routine: sum the 1's complement of the 16-bit words. I thought it was legal ANSI. I guess I have modified the code a little from the original that I'm getting right now.... ok. Here it is. static u32_t chksum(void *dataptr, int len) { u32_t acc; for(acc = 0; len > 1; len -= 2) { acc += *((u16_t *)dataptr)++; } /* add up any odd byte */ if(len == 1) { acc += htons((u16_t)((*(u8_t *)dataptr) & 0xff) << 8); DEBUGF(INET_DEBUG, ("inet: chksum: odd byte %d\n", *(u8_t *)dataptr)); } return acc; } This portion of code is supposed to be ANSI. Copyright note: The above code snippet is from lwIP stack by Adam Dunkels / SICS. Felipe ---------------------------------------------------------------------- Comment By: Johan Knol (johanknol) Date: 2003-04-08 09:59 Message: Logged In: YES user_id=63512 This needs a second thought, disabled the "fix" in SDCCicode.c:153 ---------------------------------------------------------------------- Comment By: Nobody/Anonymous (nobody) Date: 2003-04-08 08:53 Message: Logged In: NO [tim@twlinux tim]$ gcc -Wall -ansi -pedantic test.c test.c:8: warning: return type of `main' is not `int' test.c: In function `main': test.c:13: invalid lvalue in increment How did you get this to compile with gcc? ---------------------------------------------------------------------- Comment By: Johan Knol (johanknol) Date: 2003-04-08 08:00 Message: Logged In: YES user_id=63512 fixed in SDCCicode.c:1.152 ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=100599&aid=604575&group_id=599 |