Can someone please tell me what this operator does?

P

Pep

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 :?
 
L

Lucien Coffe

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
 
Y

Yakov Gerlovin

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

Rui Maciel

Pep said:
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,901
Latest member
Noble71S45

Latest Threads

Top