[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Another nil/false proposal (long)
- From: "John Belmonte" <jvb@...>
- Date: Tue, 15 Jan 2002 12:45:10 +0900
(this message is !Lua)
RLake wrote:
> Not is not "!". I don't know whose dumb idea that was, but there is
> no human language I know in which ! indicates negation. Such
> people could use the C++ idiom !!)
I don't know the origins either. In algebra notation we put a bar on top of
the symbol. Since the primitive terminals of yesterday (and even today)
couldn't do this, perhaps the bar fell to the side and broke.
> Q: Why does one use !!foo in C++ ??
>
> A: Because it gives you a true boolean. foo could have been
> any type with a Boolean conversion. There is no rule that
> says, for example, that the "false" or "null" pointer is
> represented by a bitstring consisting entirely of 0s. However
> !!foo is either 0 or 1. I would say that this is amongst the
> reasons I program in C when forced to, not for pleasure, but
> perhaps 90% of the programmers in the world it's normal.
I don't use !! in C++. Perhaps this is an outdated idiom? The correct
thing to do in modern C++ is "static_cast<bool>(foo)" or just "bool(foo)" if
you are lazy and don't care about undefined conversions.
-John