From: Marc Lindahl on 22 Jun 2005 20:37 OK I'll buy that :) You know, dollars to donuts it compiles to the exact same machine language... On Jun 22, 2005, at 5:37 PM, Chris Wilson wrote: > Hi Marc, > >>> if((res = strcmp( A->field1, B->field1 ))) >>> return(res); >> >> shouldn't it be a '==' instead of a '='? > > Are you sure? It looks like a standard (if counter-intuitive) C idiom > for assignment and comparison in the same statement, perhaps better > written as: > > res = strcmp( A->field1, B->field1 ); > if (res) > return res; > > > But it has the same effect. > > Cheers, Chris. > -- > _ ___ __ _ > / __/ / ,__(_)_ | Chris Wilson <0000 at qwirx.com> - Cambs UK | > / (_/ ,\/ _/ /_ \ | Security/C/C++/Java/Perl/SQL/HTML Developer | > \ _/_/_/_//_/___/ | We are GNU-free your mind-and your software | > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: wx-users-unsubscribe(a)lists.wxwidgets.org > For additional commands, e-mail: wx-users-help(a)lists.wxwidgets.org > --------------------------------------------------------------------- To unsubscribe, e-mail: wx-users-unsubscribe(a)lists.wxwidgets.org For additional commands, e-mail: wx-users-help(a)lists.wxwidgets.org
From: Gad Zooks on 27 Jun 2005 05:28 On Thu, 23 Jun 2005 00:37:58 +0000 (UTC), marc(a)bowery.com (Marc Lindahl) wrote: >OK I'll buy that :) >You know, dollars to donuts it compiles to the exact same machine >language... > >On Jun 22, 2005, at 5:37 PM, Chris Wilson wrote: > >> Hi Marc, >> >>>> if((res = strcmp( A->field1, B->field1 ))) >>>> return(res); >>> >>> shouldn't it be a '==' instead of a '='? >> >> Are you sure? It looks like a standard (if counter-intuitive) C idiom >> for assignment and comparison in the same statement, perhaps better >> written as: >> >> res = strcmp( A->field1, B->field1 ); >> if (res) >> return res; >> >> It is indeed an old C programmers way of assigning and testing in a single statement. I am a bit surprised to find that under Visual C++ it generates warning messages so I really ought to stop using it, but dammit, I like it. Mind you I am slow to change, I never really forgave the ANSI group for spoiling my favouite variable swapping routine which allowed me to swap the contents of two variables without declaring a third to use as a temp, thus: #define SWAP(A,B) { A^=B; B^=A; A^=B } which prior to ANSI standards would work for any variable type (not arrays or strucutres but ints, chars, pointers etc) but post ANSI will only work for ints. Bah! I remember the good old days ....... when types were unsafe and men were real men ..... and women were glad of it. Gad
From: David Elliott on 27 Jun 2005 12:52
On Jun 27, 2005, at 5:28 AM, Gad Zooks wrote: > > On Thu, 23 Jun 2005 00:37:58 +0000 (UTC), marc(a)bowery.com (Marc > Lindahl) wrote: > > >> OK I'll buy that :) >> You know, dollars to donuts it compiles to the exact same machine >> language... >> >> On Jun 22, 2005, at 5:37 PM, Chris Wilson wrote: >> >> >>> Hi Marc, >>> >>> >>>>> if((res = strcmp( A->field1, B->field1 ))) >>>>> return(res); >>>>> >>>> >>>> shouldn't it be a '==' instead of a '='? >>>> >>> >>> Are you sure? It looks like a standard (if counter-intuitive) C >>> idiom >>> for assignment and comparison in the same statement, perhaps better >>> written as: >>> >>> res = strcmp( A->field1, B->field1 ); >>> if (res) >>> return res; >>> >>> >>> > > It is indeed an old C programmers way of assigning and testing in a > single statement. I am a bit surprised to find that under Visual C++ > it generates warning messages so I really ought to stop using it, but > dammit, I like it. > I'm not sure it's an "old" way of doing it. I use it from time to time and don't see a problem with it. GCC won't warn you about it so long as you enclose the assignment within parenthesis. And I _think_ you can get Visual C to not complain if you do if( (result = doSomething()) != 0) because it will know then that you really did intend to do a test. If not then go get a less stupid compiler. -Dave --------------------------------------------------------------------- To unsubscribe, e-mail: wx-users-unsubscribe(a)lists.wxwidgets.org For additional commands, e-mail: wx-users-help(a)lists.wxwidgets.org |