Prev: Displaying property menu at runtime
Next: Delay Methods
From: Tom Shelton on 20 Jul 2010 14:17 It happens that dpb formulated : > 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. > C++ does define a true boolean now. But, the old convention seems to be still alive as far as I can tell. -- Tom Shelton
From: Tom Shelton on 20 Jul 2010 14:22 Paul Clement laid this down on his screen : > 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. Ah... K & R C :) function(x) : int { return x; } Fun stuff that :) I can't remember if the above is completely accurate to the original C - but, in my first job I had to work with some old C code written on some old motorola unix sysstems... So, I got to play quite a bit with some of the old style K&R stuff - but that was almost 10 years ago now :) -- Tom Shelton
From: dpb on 20 Jul 2010 14:31 Tom Shelton wrote: > It happens that dpb formulated : >> 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. >> > > C++ does define a true boolean now. But, the old convention seems to be > still alive as far as I can tell. I don't think there are enough silver bullets or wooden stakes to ever slay that particular creature...it is an idiom/convention too ingrained into C/C++ vernacular to ever die. And, afaik, TRUE is still equated to nonzero not only to the value of the _one_true_TRUE_ (tm) and will have to remain because otherwise it breaks almost every C/C++ code in existence. --
From: Karl E. Peterson on 20 Jul 2010 15:01 Paul Clement expressed precisely : > 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. ;-) Generally, no. They make E&C a bit more troublesome. HTH! -- ..NET: It's About Trust! http://vfred.mvps.org
From: ralph on 20 Jul 2010 16:06
On Tue, 20 Jul 2010 12:22:48 -0600, Tom Shelton <tom_shelton(a)comcast.invalid> wrote: >Ah... K & R C :) > >function(x) : int { > return x; >} > >Fun stuff that :) I can't remember if the above is completely accurate >to the original C - but, in my first job I had to work with some old C >code written on some old motorola unix sysstems... So, I got to play >quite a bit with some of the old style K&R stuff - but that was almost >10 years ago now :) Don't remember any C dialects that used a colon in that context. But there were a ton of compilers back then. Normally you would write that as ... int function(x) int x; { return x; } However, int was the default for both arguments and returns, so it could have just been written ... function(x) { return x; } Later, "ANSI C" came along which allowed you to make your declarations in place. ... int function(int x) { return x; } It occasionally comes as a surprise to many programmers that there was no C standard until 1986 (and not universally adopted till several years after that), and "K&R" never was a true standard though often labeled as one. However, most compilers consider the K&R as the core language requirement, and most of what was to become "ANSI C" was already in use via vendor extensions long before 1986. What fascinated me back then was how quickly "ANSI C" caught on, since then as now the C community was populated with the most arrogant pompus obnoxious malaperts ever to grace this planet. (And I should know, I was one of them. <g>) Instead they vented their viciousness against the proper placement of braces, indents, naming conventions, and editors. -ralph |