From: Gerhard Menzl on
Jeff Schwab wrote:

>>>Conditions in C++ don't test for truth, they test for non-zero.
>>
>>This is very *very* wrong (as I'm sure the 20 replies before mine
>>would clarify :-))
>
> Oh, very, *very* wrong. I'm sure none of my loops or if-statements
> work properly. All these years... I've been duped!

Carlos is right. Except for switch statements, conditions in C++ are
either of type bool, implicitly convertible to bool, or ill-formed. See
6.4/4.

You have not been duped, you just seem to have been unaware of implicit
conversions.

--
Gerhard Menzl

#dogma int main ()

Humans may reply by replacing the thermal post part of my e-mail address
with "kapsch" and the top level domain part with "net".

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

From: chris jefferson on
Jeff Schwab wrote:

>
> T* p = NULL; // T* p = 0;

Actually, on gcc,

T* p = NULL; preprocesses to
T* p = __null;

If I write

int i = 5 + NULL;
int j = NULL;

I get
temp.cc:5: warning: NULL used in arithmetic
temp.cc:6: warning: converting to non-pointer type 'int' from NULL

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

From: ThosRTanner on
OK, let me think

1) Code written using the "almost anything can be coerced to a boolean"
paradigm. Particularly:

a) Assignment in an if: if (a = b) { ... }
b) Using ! to turn non-booleans into booleans, as in if (!(a&b)) {...}
c) As with others, I prefer if (a != NULL) to if (a)

2) Using #include <not-a-system-header>
a) It won't compile on many compilers
b) When questioned, the usual answer is "because I think that header is
important"

3) People who make coding standards that say you cannot use #include
".."

4) All the bits of defined undefined behaviour in the standard (and
those people who feel that because experts understand all these
nuances, there's no need to change the language).
Current favourites are:
a) The fun you get when inheriting from a class with a non-virtual
destructor
b) order of evaluation issues
c) throwing from a destructor (not quite undefined, but utterly
suicidal)

5) The behaviour of throw when you throw something that isn't in the
functions throw specification. Included in this peeve is those people
who feel that because changing the language would cause programs to
break at compile time that would otherwise have broken unpredictably at
runtime, this must be a bad thing

6) People who insist that while(1) {...} is more efficient than for(;;)
{..}

7) Classes which consist of entirely public static functions.


[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

From: velthuijsen@hotmail.com on
Missing and/or incomplete documentation.
It's truely a joy to add something to a program wich you
basically have to reverse engineer to figure out where to fit in the
new code.

Wrong documentation
Even worse then missing documentation, at least with missing
documentation you know you've to figure it out yourself.

Abuse of or use of wrong design constructs.

Not knowing how mutexes (and other access control mechanisms) work.

Over use of classes
To many classes is just as bad as spaghetti coding. It
fragments data storage and splits actions that can be conceptually
grouped from each other.

Speaking about spaghetti code:
Designing a super-class that either contains public references/objects
to all other classes or is derived from classes that contain those
public references/objects, then in the header file that is included in
all other files define a pointer to this superclass.
What do you mean you can't do spaghetti coding with classes?
Your fellow coders will just love the hours and days they'll be
spending to figure out why altering a function in class A causes class
Y to crash when used.


[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

From: Andrei Alexandrescu (See Website For Email) on
John W. Peterson wrote:
> How about never incrementing b?

Darn, I knew I'll make a mistake someplace. I was too focused on getting
the "found" flag right. I must be bad at writing bad code :o).

Andrei

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

First  |  Prev  |  Next  |  Last
Pages: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
Prev: Special container
Next: map within map