Thread overview | ||||||
---|---|---|---|---|---|---|
|
October 08, 2002 about Warning 2: possible unintended assignment | ||||
---|---|---|---|---|
| ||||
int *ptr=...; while(*ptr++); .. At the while loop dmc gives "Warning 2: possible unintended assignment". what code is generated in this case? I mean will it work as it is expected or the optimizer will remove it, or something else. best regards rado |
October 09, 2002 Re: about Warning 2: possible unintended assignment | ||||
---|---|---|---|---|
| ||||
Posted in reply to radopas | In article <anvhit$2um5$1@digitaldaemon.com>, radopas@hotmail.com says... > >int *ptr=...; >while(*ptr++); >.. >At the while loop dmc gives "Warning 2: possible unintended assignment". dang i couldn't get that error either... did get Warning 7: possible extraneous ';' wonder what's up? i have sc.exe and dmc.exe v8.29n dated 7/24/02 22:09 while(*ptr++); hmmm...? |
October 09, 2002 Re: about Warning 2: possible unintended assignment | ||||
---|---|---|---|---|
| ||||
Posted in reply to bw | bw schrieb... > >while(*ptr++); > >.. > >At the while loop dmc gives "Warning 2: possible unintended assignment". Unintended assignment warnings will be given with code like this int tmp; int *ptr; // .... while(tmp=*ptr++) { some_code } ^^^^^^ Should this really be a assignment or was a compare intended. This was a common error I made when I moved from Pascal to C. > dang i couldn't get that error either... did get Warning 7: possible extraneous ';' > > wonder what's up? > i have sc.exe and dmc.exe v8.29n dated 7/24/02 22:09 > > while(*ptr++); hmmm...? This warning is given because the ; could have been set unintentionally, as in while(*ptr++); //<< unwanted ';' here? Function(ptr-1); The programmer want's to call Function in the while loop. But instead the Function is only called once when the while loop is finished. In both cases the code will work as written (intended). - Heinz |
October 09, 2002 Re: about Warning 2: possible unintended assignment | ||||
---|---|---|---|---|
| ||||
Posted in reply to radopas | <radopas@hotmail.com> wrote in message news:anvhit$2um5$1@digitaldaemon.com... > int *ptr=...; > while(*ptr++); > .. > At the while loop dmc gives "Warning 2: possible unintended assignment". > what code is generated in this case? > I mean will it work as it is expected or the optimizer will remove it, or > something else. It'll work fine, it's just that many programmers adopt a style avoiding assignment statements that are used as booleans. You can avoid it by writing as: while (*ptr++ != 0) ; |
Copyright © 1999-2021 by the D Language Foundation