Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Can someone please tell me what this operator does?

Reply
Thread Tools

Can someone please tell me what this operator does?

 
 
Pep
Guest
Posts: n/a
 
      09-21-2011
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
 
Reply With Quote
 
 
 
 
Lucien Coffe
Guest
Posts: n/a
 
      09-21-2011
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'
 
Reply With Quote
 
 
 
 
Lucien Coffe
Guest
Posts: n/a
 
      09-21-2011
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...._6.html#SEC116

--
perl -e 's;;{]``*%)}`_^[&)/#%(`&;;\
y;%^)([]/*#&`_{};.\100acghiklmopsz;;print'
 
Reply With Quote
 
Jorgen Grahn
Guest
Posts: n/a
 
      09-22-2011
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...._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 .
 
Reply With Quote
 
Yakov Gerlovin
Guest
Posts: n/a
 
      09-23-2011
On Sep 21, 1:48*pm, Pep <(E-Mail Removed)> 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.
 
Reply With Quote
 
Rui Maciel
Guest
Posts: n/a
 
      09-23-2011
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...._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
 
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
Can someone please tell me where I am going wrong?? Dildo Boy C Programming 6 03-06-2007 04:48 AM
HELP Can someone please tell me how to use a crossover cable! =?Utf-8?B?WmVscGhyaW4=?= Microsoft Certification 2 03-29-2006 10:20 PM
Can someone tell me why? (Unary pre and post increment operator Andreas Sheriff C++ 10 09-25-2004 02:33 AM
Can someone tell me what this syntax does please? George Styles C++ 6 01-16-2004 06:43 PM
can someone please tell me some Visual Basic websites for some help? valentin Computer Support 2 06-25-2003 05:33 PM



Advertisments