Can someone please tell me what this operator does?

Discussion in 'C++' started by Pep, Sep 21, 2011.

  1. Pep

    Pep Guest

    I inherited soem weird code that makes no sense to me :S The following
    line compiles under the gnu c++ compiler

    int requiredLength = requestedLength >? 32;

    but the windows c++ compiler rejects the >? operator and I have no
    idea what it does, nor can I find any mention of this when I google
    for the operator.

    The complete code section has been modified with #ifdef to get it to
    work via the windows c++ compiler


    #ifdef WIN32_COMPILER
    int bar = foo;

    if (bar < 32)
    {
    bar = 32;
    }
    #else
    int bar = foo >? 32;
    #endif

    So the >? operator is expanded in the windows code to a check for bar
    less than 32 and if true assign 32 to bar. Yet the condensed gnu
    version of the code uses a greater than operator and presumably the
    ternary operator :?
     
    Pep, Sep 21, 2011
    #1
    1. Advertising

  2. Pep

    Lucien Coffe Guest

    Pep wrote :

    > I inherited soem weird code that makes no sense to me :S The following
    > line compiles under the gnu c++ compiler
    >
    > int requiredLength = requestedLength >? 32;
    >
    > but the windows c++ compiler rejects the >? operator and I have no idea
    > what it does, nor can I find any mention of this when I google for the
    > operator.
    >
    > The complete code section has been modified with #ifdef to get it to
    > work via the windows c++ compiler
    >
    >
    > #ifdef WIN32_COMPILER
    > int bar = foo;
    >
    > if (bar < 32)
    > {
    > bar = 32;
    > }
    > #else
    > int bar = foo >? 32;
    > #endif
    >
    > So the >? operator is expanded in the windows code to a check for bar
    > less than 32 and if true assign 32 to bar. Yet the condensed gnu version
    > of the code uses a greater than operator and presumably the ternary
    > operator :?


    What version of gcc are you using again?
    Got this with gcc 4.2.4, 4.3.4, 4.5.1 :
    http://ideone.com/1xNEK

    --
    perl -e 's;;{]``*%)}`_^[&)/#%(`&;;\
    y;%^)([]/*#&`_{};.\100acghiklmopsz;;print'
     
    Lucien Coffe, Sep 21, 2011
    #2
    1. Advertising

  3. Pep

    Lucien Coffe Guest

    Lucien Coffe wrote :

    > Pep wrote :
    >
    >> I inherited soem weird code that makes no sense to me :S The following
    >> line compiles under the gnu c++ compiler
    >>
    >> int requiredLength = requestedLength >? 32;
    >>
    >> but the windows c++ compiler rejects the >? operator and I have no idea
    >> what it does, nor can I find any mention of this when I google for the
    >> operator.
    >>
    >> The complete code section has been modified with #ifdef to get it to
    >> work via the windows c++ compiler
    >>
    >>
    >> #ifdef WIN32_COMPILER
    >> int bar = foo;
    >>
    >> if (bar < 32)
    >> {
    >> bar = 32;
    >> }
    >> #else
    >> int bar = foo >? 32;
    >> #endif
    >>
    >> So the >? operator is expanded in the windows code to a check for bar
    >> less than 32 and if true assign 32 to bar. Yet the condensed gnu
    >> version of the code uses a greater than operator and presumably the
    >> ternary operator :?

    >
    > What version of gcc are you using again? Got this with gcc 4.2.4, 4.3.4,
    > 4.5.1 : http://ideone.com/1xNEK



    They are called "minimum/maximum operators", and are deprtecated.

    http://gcc.gnu.org/onlinedocs/gcc-3.0.4/gcc_6.html#SEC116

    --
    perl -e 's;;{]``*%)}`_^[&)/#%(`&;;\
    y;%^)([]/*#&`_{};.\100acghiklmopsz;;print'
     
    Lucien Coffe, Sep 21, 2011
    #3
  4. Pep

    Jorgen Grahn Guest

    On Wed, 2011-09-21, Lucien Coffe wrote:
    > Lucien Coffe wrote :
    >
    >> Pep wrote :
    >>
    >>> I inherited soem weird code that makes no sense to me :S The following
    >>> line compiles under the gnu c++ compiler
    >>>
    >>> int requiredLength = requestedLength >? 32;

    ....
    >
    > They are called "minimum/maximum operators", and are deprtecated.
    >
    > http://gcc.gnu.org/onlinedocs/gcc-3.0.4/gcc_6.html#SEC116


    And they don't work in g++ either, if you tell it to compile standard
    C++.

    /Jorgen

    --
    // Jorgen Grahn <grahn@ Oo o. . .
    \X/ snipabacken.se> O o .
     
    Jorgen Grahn, Sep 22, 2011
    #4
  5. On Sep 21, 1:48 pm, Pep <> wrote:
    > I inherited soem weird code that makes no sense to me :S The following
    > line compiles under the gnu c++ compiler
    >
    > int requiredLength = requestedLength >? 32;


    It wouldn't compile under g++ 4.5.3

    > The complete code section has been modified with #ifdef to get it to
    > work via the windows c++ compiler
    >
    > #ifdef WIN32_COMPILER
    >         int bar = foo;
    >
    >         if (bar < 32)
    >         {
    >                 bar = 32;
    >         }
    > #else
    >         int bar = foo >? 32;
    > #endif
    >


    Why would you do that? Why not to use a standard, portable std::max?
    It does not have any side effects, like MAX macro.
    If, for some reason, you can't (or don't want to) use STL, just change
    it to

    int requiredLength = requestedLength > 32 ? requestedLength : 32;

    I strongly suggest to avoid using platform/compiler dependent code for
    such simple things.
     
    Yakov Gerlovin, Sep 23, 2011
    #5
  6. Pep

    Rui Maciel Guest

    Pep wrote:

    > I inherited soem weird code that makes no sense to me :S The following
    > line compiles under the gnu c++ compiler
    >
    > int requiredLength = requestedLength >? 32;
    >
    > but the windows c++ compiler rejects the >? operator and I have no
    > idea what it does, nor can I find any mention of this when I google
    > for the operator.
    >
    > The complete code section has been modified with #ifdef to get it to
    > work via the windows c++ compiler
    >
    >
    > #ifdef WIN32_COMPILER
    > int bar = foo;
    >
    > if (bar < 32)
    > {
    > bar = 32;
    > }
    > #else
    > int bar = foo >? 32;
    > #endif
    >
    > So the >? operator is expanded in the windows code to a check for bar
    > less than 32 and if true assign 32 to bar. Yet the condensed gnu
    > version of the code uses a greater than operator and presumably the
    > ternary operator :?



    It's GNU's maximum operator. See:

    http://gcc.gnu.org/onlinedocs/gcc-2.95.3/gcc_5.html#SEC107


    Just strip every instance of these funny operators out of your code and
    replace them with decent, standard alterantives such as std::max, as Yakov
    Gerlovin suggested.


    Rui Maciel
     
    Rui Maciel, Sep 23, 2011
    #6
    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. George Styles
    Replies:
    6
    Views:
    1,681
    jeffc
    Jan 16, 2004
  2. Andreas Sheriff
    Replies:
    10
    Views:
    731
    Jack Klein
    Sep 25, 2004
  3. Dildo Boy
    Replies:
    6
    Views:
    320
    Flash Gordon
    Mar 6, 2007
  4. E-Dot
    Replies:
    15
    Views:
    524
  5. Jim
    Replies:
    7
    Views:
    299
    christian.bau
    Mar 22, 2008
Loading...

Share This Page