On 1/31/2013 5:39 AM, Valentin Bernard wrote:
> On 25 jan, 01:27, Victor Bazarov <v.baza...@comcast.invalid> wrote:
>> On 1/24/2013 4:49 PM, Paul N wrote:
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>> On Jan 24, 7:23 pm, Andrey Tarasevich <andreytarasev...@hotmail.com>
>>> wrote:
>>>> On 1/23/2013 7:24 AM, Bint wrote:
>>
>>>>> I haven't seen this syntax before. What does "!!" do in C++?
>>
>>>> "Syntax"? There's no notable "syntax" of any kind involved here.
>>
>>>> `!!` is just an unary `!` followed by another unary `!`.
>>
>>>> Now, if you know what `!` operator does (consult your favorite C or C++
>>>> book if you don't), then you should realize that the `!!` combination
>>>> implements "is non-zero" functionality: it evaluates to `true` for
>>>> non-zero argument, and to `false` otherwise.
>>
>>> Andrey - what you say is true if you *know* there is no !! operator,
>>
>> This should really be easy to "know" upon opening any C++ book worth the
>> paper it's printed on, on the page where all the operators are put in a
>> table or a list.
>>
>>> but the OP presumably didn't know (or at least wasn't sure) of this.
>>
>>> After all, there is a unary - operator, but it doesn't follow that --x
>>> will change the sign of x twice, returning the original value, does
>>> it?
>>
>> Yes, but the same list of operators in the C++ book the OP is supposed
>> to have undoubtedly includes -- as a single operator, and it does NOT
>> include !! (like it does not include ^^ or **, for instance).
>>
>> As an exercise, it's recommended to try to understand what the
>> expression a-----b "does" (syntactic meaning), and whether it should
>> compile (advanced topic for those who try to understand lvalues) for,
>> say, integral types of 'a' and 'b'.
>>
>> V
>> --
>> I do not respond to top-posted replies, please don't ask
>
> Interesting...
>
> ROT13: Vg snvyf jvgu "reebe P2105: '--' arrqf y-inyhr". Nccneragyl vg
> gevrf gb qrperzrag "-o". "n--- --o" jbexf. V jbhyq unir gubhtug gur
> bevtvany rkcerffvba jbhyq unir orra vagrecergrq nf "(n--) - (--o)".
The expression is parsed as ((a--) --) - b. The second decrement is
what doesn't work because the compiler is trying to apply it to the
result of 'a--', which is not an lvalue.
I thought that one had appeared (in a slightly different form) as one of
Herb Sutter's "gotcha of the week" some time ago, but upon a brief look
at gotw.ca/gotw, I couldn't find it. Perhaps it was somewhere else.
The question was something like "how many different operator symbols in
a row are legal in C++?"
V
--
I do not respond to top-posted replies, please don't ask
|