views:

276

answers:

5

Could anyone help me to understand following line of code:

sol< ?=f((1<< n)-1,i,0)+abs(P[i])*price;

I am studying an algorithm written using c++ and it has following operator < ?= . My problem is with understanding < ?= operator. Also when I compile this code using g++ compiler , it gives error message for above line of code line of code

following is the error message returned.

Hello.cpp: In function ‘int main()’:

Hello.cpp:115: error: ‘memset’ was not declared in this scope

Hello.cpp:142: error: expected primary-expression before ‘?’ token

Hello.cpp:142: error: expected primary-expression before ‘=’ token

Hello.cpp:142: error: expected ‘:’ before ‘;’ token

Hello.cpp:142: error: expected primary-expression before ‘;’ token

Maybe < ?= it is not a single operator, but I can not understand what exactly this line of code does.

Thanks in advance for the time you spent reading this post.

A: 

This line isn't a line of code. That's why it doesn't compile. It is meaningless to ask what it does.

Marcelo Cantos
i want to know about the "< ? =" operator, I am not expecting explanation on the full line bcoz i have not included the rest of the code.
KItis
There is no `< ?=` operator; it isn't two operators either. To reiterate, this isn't code. It just resembles code.
Marcelo Cantos
http://pastebin.com/aSZCSeTZ , here is the link to full code I am referring. This code has given the first place in Google Code jam 2008. that is why i am interested to know how it works actually
KItis
A: 

Take a look at the C grammar here

The only use of ? is in the ternary operator:

conditional_expression
    : logical_or_expression
    | logical_or_expression '?' expression ':' conditional_expression
    ;

Where the ? is followed by an expression. This does not happen in your case. So your code is not a valid C.

codaddict
http://pastebin.com/aSZCSeTZ , here is the link to full c++ code I am referring
KItis
A: 

It could almost be a line of PHP code though: all it needs is remove a space to form at the end.

<?= foo(); ?>

is equivalent to

<?php echo foo(); ?>
Frank Shearar
http://pastebin.com/aSZCSeTZ this is the full c++ code i am referring here.
KItis
+18  A: 

It's a GNU extension. It's basically a "lower than" operator.

int a = 3;
a <?= 2;
cout << a << endl; // prints 2, because 2 < 3

a <?= 10;
cout << a << endl; // prints 2 as well, because 10 > 2

Read more here.

IVlad
Thanks budy , you are a Hero :)
KItis
You know, every time I think I've seen every last bit of evil from GCC, I'm pinged between the eyes with something even more evil. +1 for you. -100,000 for the GCC team. Ugh!
JUST MY correct OPINION
I compiled above code using g++ compiler, do you have some idea about why above error is returned.
KItis
@Kltis: The `<?` and `>?` have been deprecated in favor of the clearer `std::min` and `std::max`.
KennyTM
Well, to be honest I'm not really familiar with the operator myself since I never used it :). The code compiled for me on the GNU compiler however. What version are you using?
IVlad
@IVIad: i am using version 4.4.1 ubuntu version.
KItis
Oh, well, I'm using 3.4.5 on Windows. Maybe they removed it. Just replace it with a min function.
IVlad
It's been deprecated since G++ 4.0, apparently.
JUST MY correct OPINION
::::::: shivers
wilhelmtell
+1  A: 

To be clear for anyone reading this and not being able to follow; <?= and >?= are assignment versions of <? and >? which are depricated GCC extensions which served the purpose of (x>y)?x:y or (x<y)?x:y respectively.

Therefore, x <?= y; would be x = x <? y; which is x = (x<y) ? x : y;

Most compiler vendors introduce language extensions, and many make it into future language standards. Usually these extensions are either just very easy to add or make the job of writing standard libraries much easier.

nategoose
Thanx for the info
KItis