c++ - about Warning 2: possible unintended assignment
- radopas hotmail.com (9/9) Oct 08 2002 int *ptr=...;
- bw (6/10) Oct 08 2002 dang i couldn't get that error either...
- Heinz Saathoff (19/29) Oct 09 2002 Unintended assignment warnings will be given with code like this
- Walter (7/14) Oct 08 2002 It'll work fine, it's just that many programmers adopt a style avoiding
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
Oct 08 2002
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...?
Oct 08 2002
bw schrieb...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.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...?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
Oct 09 2002
<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) ;
Oct 08 2002