Re: What does !! do?

Discussion in 'C++' started by Andrey Tarasevich, Jan 24, 2013.

  1. 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
    Andrey Tarasevich, Jan 24, 2013
    #1
    1. Advertising

  2. Andrey Tarasevich

    Paul N Guest

    On Jan 24, 7:23 pm, Andrey Tarasevich <>
    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?
    Paul N, Jan 24, 2013
    #2
    1. Advertising

  3. On 1/24/2013 4:49 PM, Paul N wrote:
    > On Jan 24, 7:23 pm, Andrey Tarasevich <>
    > 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
    Victor Bazarov, Jan 25, 2013
    #3
  4. Andrey Tarasevich

    army1987 Guest

    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/>
    army1987, Jan 29, 2013
    #4
  5. Andrey Tarasevich

    army1987 Guest

    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/>
    army1987, Jan 29, 2013
    #5
  6. On 25 jan, 01:27, Victor Bazarov <> wrote:
    > On 1/24/2013 4:49 PM, Paul N wrote:
    >
    >
    >
    >
    >
    >
    >
    >
    >
    > > On Jan 24, 7:23 pm, Andrey Tarasevich <>
    > > 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.
    Valentin Bernard, Jan 31, 2013
    #6
  7. On 1/31/2013 5:39 AM, Valentin Bernard wrote:
    > On 25 jan, 01:27, Victor Bazarov <> wrote:
    >> On 1/24/2013 4:49 PM, Paul N wrote:
    >>
    >>
    >>
    >>
    >>
    >>
    >>
    >>
    >>
    >>> On Jan 24, 7:23 pm, Andrey Tarasevich <>
    >>> 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
    Victor Bazarov, Jan 31, 2013
    #7
  8. 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
    Bart van Ingen Schenau, Feb 2, 2013
    #8
  9. Andrey Tarasevich

    red floyd Guest

    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 --.
    red floyd, Feb 4, 2013
    #9
  10. 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
    Urs Thuermann, Feb 6, 2013
    #10
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Bill Johnson
    Replies:
    0
    Views:
    1,228
    Bill Johnson
    Jul 8, 2005
  2. Replies:
    3
    Views:
    472
    Ken Cox [Microsoft MVP]
    Oct 7, 2005
  3. Janet Collins
    Replies:
    0
    Views:
    1,134
    Janet Collins
    Jan 13, 2006
  4. Replies:
    1
    Views:
    832
    Juan T. Llibre
    Feb 8, 2006
  5. Alek Nazarian
    Replies:
    7
    Views:
    3,211
    Alek Nazarian
    Oct 22, 2003
Loading...

Share This Page