Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Re: What does !! do?

Reply
Thread Tools

Re: What does !! do?

 
 
Andrey Tarasevich
Guest
Posts: n/a
 
      01-24-2013
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.

--
Best regards,
Andrey Tarasevich

 
Reply With Quote
 
 
 
 
Paul N
Guest
Posts: n/a
 
      01-24-2013
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,
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?
 
Reply With Quote
 
 
 
 
Victor Bazarov
Guest
Posts: n/a
 
      01-25-2013
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
 
Reply With Quote
 
army1987
Guest
Posts: n/a
 
      01-29-2013
On Thu, 24 Jan 2013 19:27:45 -0500, Victor Bazarov wrote:

> 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'.


Rot13: Vg fubhyq pbzcvyr ohg vgf orunivbhe vf haqrsvarq. Right?



--
[ T H I S S P A C E I S F O R R E N T ]
Troppo poca cultura ci rende ignoranti, troppa ci rende folli.
-- fathermckenzie di it.cultura.linguistica.italiano
<http://xkcd.com/397/>
 
Reply With Quote
 
army1987
Guest
Posts: n/a
 
      01-29-2013
On Tue, 29 Jan 2013 10:17:33 +0000, army1987 wrote:

> On Thu, 24 Jan 2013 19:27:45 -0500, Victor Bazarov wrote:
>
>> 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'.

>
> Rot13: Vg fubhyq pbzcvyr ohg vgf orunivbhe vf haqrsvarq. Right?


(Wrong. Brain fart.)



--
[ T H I S S P A C E I S F O R R E N T ]
Troppo poca cultura ci rende ignoranti, troppa ci rende folli.
-- fathermckenzie di it.cultura.linguistica.italiano
<http://xkcd.com/397/>
 
Reply With Quote
 
Valentin Bernard
Guest
Posts: n/a
 
      01-31-2013
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)".

Cheers.
 
Reply With Quote
 
Victor Bazarov
Guest
Posts: n/a
 
      01-31-2013
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
 
Reply With Quote
 
Bart van Ingen Schenau
Guest
Posts: n/a
 
      02-02-2013
On Thu, 31 Jan 2013 09:10:36 -0500, Victor Bazarov wrote:

> 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++?"


Without intervening identifiers and without repeating yourself, this
would be among the largest:
a++,+--*&b;

(With repetitions, the longest sequence is infinitely long)

>
> V


Bart v Ingen Schenau
 
Reply With Quote
 
red floyd
Guest
Posts: n/a
 
      02-04-2013
On 2/2/2013 2:10 AM, Bart van Ingen Schenau wrote:

> Without intervening identifiers and without repeating yourself, this
> would be among the largest:
> a++,+--*&b;
>


What about
a++,!+--*&b;

You could also possibly throw in a - before the !,
and also a ! between the + and the --.

 
Reply With Quote
 
Urs Thuermann
Guest
Posts: n/a
 
      02-06-2013
red floyd <> writes:

> On 2/2/2013 2:10 AM, Bart van Ingen Schenau wrote:
>
> > Without intervening identifiers and without repeating yourself, this
> > would be among the largest:
> > a++,+--*&b;
> >

>
> What about
> a++,!+--*&b;
>
> You could also possibly throw in a - before the !,
> and also a ! between the + and the --.


Still not the largest:

int &(**p)(), a;
p[0]()++>=~!-+--*&a;

BTW, sizeof is also an operator, so you can add that, too.


urs
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
.NET 2.0 ASPx Page does not load, but HTM does prabhupr@hotmail.com ASP .Net 1 02-08-2006 12:57 PM
Button OnClick does not fire on first postback, but does on second Janet Collins ASP .Net 0 01-13-2006 10:08 PM
Does the 2.0 Framework come out when Visual Studio .NET 2005 does? needin4mation@gmail.com ASP .Net 3 10-07-2005 12:55 AM
CS0234 Global does not exist ... but it genuinely does Bill Johnson ASP .Net 0 07-08-2005 06:34 PM
Does no one else think microsoft does a poor job? =?Utf-8?B?SmVyZW15IEx1bmRncmVu?= Wireless Networking 2 11-20-2004 12:17 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57