Prev: Displaying property menu at runtime
Next: Delay Methods
From: Tom Shelton on 20 Jul 2010 13:48 Paul Clement formulated on Tuesday : > On Tue, 20 Jul 2010 09:02:19 -0600, Tom Shelton <tom_shelton(a)comcast.invalid> > wrote: > > � Paul Clement was thinking very hard : > � > On Mon, 19 Jul 2010 21:28:37 -0400, "Kevin Provance" <k(a)p.c> wrote: > � > > � > � Hey C++ guys, what is the advantage or purpose of this? > � > � > � > � If (FALSE == SomeFunction()) > � > � { > � > � ... > � > � } > � > � > � > � Why put FALSE == instead of the function first, like we usually do? > � > > � > Looks like the Yoda School of Programming to me. Coded properly, the > � > comparison to FALSE isn't even necessary. > � > > � > � It's C++ code.... Older C++ didn't define a bool type or have any > � concept of a boolean value. That mades these types of comparisons > � necessary, and the reverse test was to prevent the old bug of > � accidently doing an assignment in the test. > > So let me get this straight... > > "If (FALSE)" in C++ evaluates to True or is it an invalid statement? FALSE is not a C/C++ keyword. Most likely, someone has used a #define to equate FALSE with 0. #define FALSE 0 Remember, in C/C++ - false = 0, true is non-zero. > I > haven't work with an older C-language in over 25 years so I can't recall how > this functions. > > It's still backwards with respect to readability. ;-) It is - but, with respect to code saftey, it makes a lot of sense. -- Tom Shelton
From: Karl E. Peterson on 20 Jul 2010 13:56 Paul Clement formulated on Tuesday : > It's still backwards with respect to readability. ;-) Only if your screen is infinitely wide, or you just call functions with very short parameter lists. -- ..NET: It's About Trust! http://vfred.mvps.org
From: Paul Clement on 20 Jul 2010 14:02 On Tue, 20 Jul 2010 10:56:45 -0700, Karl E. Peterson <karl(a)exmvps.org> wrote: � > It's still backwards with respect to readability. ;-) � � Only if your screen is infinitely wide, or you just call functions with � very short parameter lists. Or you use line continuation characters. ;-) Paul ~~~~ Microsoft MVP (Visual Basic)
From: Paul Clement on 20 Jul 2010 14:06 On Tue, 20 Jul 2010 11:48:47 -0600, Tom Shelton <tom_shelton(a)comcast.invalid> wrote: � > � > Looks like the Yoda School of Programming to me. Coded properly, the � > � > comparison to FALSE isn't even necessary. � > � > � > � � > � It's C++ code.... Older C++ didn't define a bool type or have any � > � concept of a boolean value. That mades these types of comparisons � > � necessary, and the reverse test was to prevent the old bug of � > � accidently doing an assignment in the test. � > � > So let me get this straight... � > � > "If (FALSE)" in C++ evaluates to True or is it an invalid statement? � � FALSE is not a C/C++ keyword. Most likely, someone has used a #define � to equate FALSE with 0. � � #define FALSE 0 � � Remember, in C/C++ - false = 0, true is non-zero. I try to remember as little as possible about the C language, although I do still have my first edition Kernighan and Ritchie book. � > I � > haven't work with an older C-language in over 25 years so I can't recall how � > this functions. � > � > It's still backwards with respect to readability. ;-) � � It is - but, with respect to code saftey, it makes a lot of sense. I guess you have to be a C-programmer. ;-) Thanks for the info. Paul ~~~~ Microsoft MVP (Visual Basic)
From: dpb on 20 Jul 2010 14:13
Paul Clement wrote: .... > "If (FALSE)" in C++ evaluates to True or is it an invalid statement? ... Neither... As noted by somebody else, C++ initially (I don't know about latest Standard) didn't have a Boolean intrinsic type and used the C convention of any nonzero value is TRUE/0 is FALSE. The statement was FALSE==function() which is true But, the logical NOT operator, "!" as opposed to the bitwise NOT "~" turns any nonzero value to zero and zero to 1. So, !FALSE == TRUE -- |