what does <?= meaning in C++ [duplicate] - c++

This question already has answers here:
Closed 11 years ago.
Possible Duplicates:
C++ weird usage of conditional operator (>?=)
C extension: <? and >? operators
When i read a C++ code,i see the following lines:
void add(double v) { min <?= v; max >?= v; StatFig::add(v); }
What does the
>?=
means?
Thanks.

Answered right here: Link.
As explained by the great answer there which i in no way take credit for, it's a deprecated GCC extension, and in no way standard C++. Avoid.

There is a list of operators in C++ on wikipedia, but it's not in here, so maybe it's defined elsewhere in the code you read.
My guess would be that's it's an assignement operator that checks if the value is lower/higher than a certain threshold, and if so assigns that threshold to the variable. Or something
In other words, min <?= v might be equivalent to min=((min<v)?min:v), but that's just a guess.

Related

Double increment on an integer variable, does it work as intended? [duplicate]

This question already has answers here:
Multiple preincrement operations on a variable in C++(C ?)
(2 answers)
Closed 6 years ago.
I have some code with lines which increment a counter.
++ count;
Sometimes I have an if condition which means I should increment count by 2.
count += 2;
Does "double increment'ing" work in the same way?
++ ++ count;
It would be helpful to know if both C and C++ compilers interpret this the same way.
As this is clearly syntactically correct, the question that remains is: "Is this UB because of unsequenced writes?"
It is not (in C++11 and later) because
5) The side effect of the built-in pre-increment and pre-decrement operators is sequenced before its value computation (implicit rule due to definition as compound assignment)
(From here)
So the code is fine as of C++11.
However, the sequencing rules were different before that, and pre-C++11, the code actually has UB.
In C, that code does not even compile.
The fact that the behavior is different between C and C++ and even between different C++ standards and that this question arises in the first place is a hint that the simple count += 2; is the safer and more readable version. You should prefer it over the "cute and clever" ++ ++count;.
There are two methods. One that obviously works, one where you have to ask a question on StackOverflow. There are comments saying "in C++ 11 or later"... How sure are you that your C++ code runs with C++ 11 and not something older? Even if you use extensions that were not part of an earlier language, your language could be C++0x with some extensions.
Clearly you shouldn't care whether the second method works or not, but use the one that obviously works.

Comparing bool with 1 in C++ [duplicate]

This question already has answers here:
Can I assume (bool)true == (int)1 for any C++ compiler?
(5 answers)
Closed 7 years ago.
Is it correct to compare bool to 1?
In a legacy code I find often:
if (xyz.isCounterActive() == 1)
where sCounterActive() returns bool.
Obviously, if ( xyz.isCounterActive() ) is sufficient, but If I change this, I don't know which side-effects it may cause. Software is big, buggy but the customer insists, that it is working.
Compiler is VS2008
In this case result of xyz.isCounterActive() will be implicitly converted to int. There're many rules of implicit conversion, which can be found here, for example.
Probably signature of isCounterActive changed since it was introduced, and the one, who changed it, forgot to modify all isCounterActive calls.

a=a++ wondering answer of visual studio? [duplicate]

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
is i=i++ truly a undefined behavior?
i just want too explain ++ and -- to my students and show them some code about them in visual studio 2010
I just test this code on it
int main(){
int a=3;
int b=3;
a=a++;
cout<<a<<endl;
cout<<b++<<endl;
}
I expect that both of cout print 3 but the first cout print 4!!!!
I test it in g++ and both of couts print 3...
what's wrong???
The behavior of a=a++ is undefined. If you'd like to increment a, use a++ instead.
http://www.slideshare.net/olvemaudal/deep-c
Read about sequence points.
a=a++; is not well defined. Don't use it.
You are only allowed do one assignment within one sequence point in C++ IIRC. So this is undefined. The following presentation discusses this issue in deep http://www.slideshare.net/olvemaudal/deep-c .

Operator <?= in C/C++ [duplicate]

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
C extension: <? and >? operators
What does the >?= operator mean?
I was googling some C++ codes on the internet and just found this:
num <?= num2-num3+num4;
Does anyone knows what this operator stands for? I googled for it but found anything.
It was a GCC extension at some point, now removed. It is the assignment version of <? which was simply the minimum operator. So that code reads "set num to num2-num3+num4 if that is smaller than num". In standard C++:
num = std::min(num, num2-num3+num4);
It's a gcc extension, basically means
num = std::min(num, rhs);

What is <?= in C++? [duplicate]

This question already has answers here:
Closed 12 years ago.
Possible Duplicate:
C extension: <? and >? operators
Take a look at the top answer (by sclo) to problem D of this Google Code Jam. It's C++ code, it must have compiled, and it contains statements such as this one:
double& ret = F[mask][cur][b];
if(j==cur) {
ret<?=f(tmp,j,b||bad[i])+M[cur][i]; // WTF is <?= ???
}
This doesn't compile in my Visual Studio 2008. What does the <?= mean?
It's a gcc extension: C extension: <? and >? operators
Recent manuals say:
The G++ minimum and maximum operators (‘<?’ and ‘>?’) and their compound forms (‘<?=’) and ‘>?=’) have been deprecated and are now removed from G++. Code using these operators should be modified to use std::min and std::max instead...
It's simply not valid C++. < Might be less than, an open angle bracket for a template argument list, or the start of a digraph however non of those can be followed by ?, then =.
It's a now deprecated g++ extension to the c++ language.
a <? b
is the minimum, returning the smaller of the numeric values a and b;
a >? b
is the maximum, returning the larger of the numeric values a and b.
There are also compound versions
<?=
and
>?=
that do assignment as well.
It doesn't compile also with GCC, and I've never heard of an operator <?=.
Anyway I would hazard a guess that a<?=b could have a semantics like: a = (a<b) ? b : a, but again, this is just a guess.