Hi,
I have such code:
Can anyone explan what does this operator <?= do?Code:for(int i=0;i++<limit; maxx <?= rt + tt)
{
...
}
Thanks.
Printable View
Hi,
I have such code:
Can anyone explan what does this operator <?= do?Code:for(int i=0;i++<limit; maxx <?= rt + tt)
{
...
}
Thanks.
I don't think that's valid code. (Although it might be a digraph I don't know about.)
Well, I compiled it and it works fine.
Regards.
Ah! I know! <? is !. So <?= is the same as !=.
Thanks, is there any reason of using something like that ?
Obfuscation perhaps..Quote:
Originally Posted by apacz
There are contests to have the most obscure code, or simply to have the most obsure code (encrypted so it couldnt be understood :rolleyes: )
Sweetie, '?' is the ternary operator, otherwise known as the conditional operator. It's called 'ternary' because it works with THREE operands...unlike something like '+' which works with two: (x+y).
This is the alternative to if/else statements: it reads: "If x > y, assign x's value to z. Else, assign z the value of y."Code:int x=2, y=5, z=0; //Our three operands
z = (x > y) ? (x:y); //Assign z to the bigger one.
How does that work in the situation its being used here?
if maxx is 0, assign it to rt + tt? I'm confused already.Code:maxx <?= rt + tt
How does that work in the situation its being used here?
if maxx is 0, assign it to rt + tt? I'm confused already.Code:maxx <?= rt + tt
It cant be != like dwks said though, because its in the third section of the for statement..
<? is described as a trigraph. The purpose of trigraphs is to allow programmers to work with keyboards that do not support certain characters. Most common scenario is on keyboards designed for non-english speakers (eg Scandinavian languages) <? expands to an exclamation mark (!)
In this case it is indeed a digraph take means !
However it is not defined in the standard so use at your own risk.
>>However it is not defined in the standard so use at your own risk.
ok mom.
why is everyone so anal about standard code?
his own risk? a bit harsh a word considering all he wanted to know what what it meant.
Ya, i'm just a bit annoyed right now at everyone harrassing me about "why are you writing it that way."
Because not everyone in the world uses the same compiler or OS. By following the standard you help ensure that the program will run as intended regardless of the machine. Of course there are times when the standard has to go out the window to solve a problem. However the likelyhood of someone posting a question on this board in which that would be the case is pretty slim.Quote:
Originally Posted by jrahhali
Now how about you tell me why you think you shouldn't follow the standard?
Edit: Also about getting annoyed about people asking why you did something a certain way: Get used to it. You should be confident enough to explain exactly why you did something a particular way. And that doesn't go just for programming but for all areas of your work. When I worked as a switchboard tech I was asked quite regularly how I came to a conclusion and why I went with a particular path for solving the problem.
>>Now how about you tell me why you think you shouldn't follow the standard?
But for his purposes, he wanted to know what it meant.
edit: nvm..nvm. bye.
When people say "use at your own" it doesnt just mean the OP, its anyone reading this to know that information. Also he is using that code apparently, and if using <? is unsafe I'm sure you would want to at least know.
Anyway, question... what exactly the purpose of the third statement in this for loop?
Its not even in the condition statement.Code:for(int i = 0; i++ < limit; maxx != rt + tt)
{
...
}
I would imagine maxx would be used inside the loop.
Dae.IQ = Dae.IQ - 20;Quote:
Originally Posted by Thantos
I don't know what you mean. Of course its possible maxx was used inside the loop, but what does stating maxx != rt + tt every increment do? its not a condition, its a statement.. right?
Its not a condition, its just.. out there.. for what reason?Code:for(int i = 0; i++ < limit; )
{
maxx != rt + tt;
}
Sorry I cant see any reason for why its there, other than none.
You tell me where it states that the third part of the for loop has to have anything to do with the first two parts. Heck I remember some interesting for loops posted on this board by some very bored programmers.
I'm not saying the third part of the for loop has to have anything to do with the others. I am saying that the first part of the for loop only occurs once (creation), at the beginning, of the for loop, the second part is the condition that is checked if still 1 (true) at the end of each loop, and the third is something that you want to occur at the end of every loop. Now why would you want 'maxx != rt + tt' to occur at the end of every loop? its not attached to an if statement, so there would be no purpose to it.. right? wrong? thats what I'm wondering.Quote:
Originally Posted by Thantos
Code:for(int i = 0; i++ < limit; maxx != rt + tt)
{
...
}
is equal to:
for(int i = 0; i++ < limit; )
{
maxx != rt + tt;
}
Since its a condition it should be in the second part of the for loop, or be attached to an if statement:Code:for(int i = 0; i++ < limit; maxx != rt + tt)
{
...
}
is equal to:
for(int i = 0; ; maxx != rt + tt)
{
if(!(i++ < limit))
break;
}
Code:for(int i = 0; i++ < limit; if(maxx != rt + tt) break)
{
...
}
is equal to:
for(int i = 0; i++ < limit; )
{
if(maxx != rt + tt)
break;
}
Who knows why they did it, its probably just a mistake they made, but really who cares?
It's actually a GCCism. a <?= b means the same as a < b ? a : b. In english, assign the minimum of a and b to a. You see stuff like that a lot in Topcoder from people trying to squeeze every second of time in their solutions.
I only wondered because half the people said it was short for !, and the other half said it was y > x ? x : y. The way its placed it doesnt make sense to be a trigraph. I guess with SilentStrike's reply thats right, that makes sense now.Quote:
Originally Posted by Thantos
> from people trying to squeeze every second of time in their solutions.
Gotta be a real moron to believe that the number of characters your program occupies has anything to do with the performance of the code.
Do they really believe that since a <?= b takes fewer characters than a < b ? a : b, that the compiler will generate fewer compare instructions or branch instructions?
Yes, you are correct; it is true that idiots exist. Either the programmer's an idiot, or the compiler creator is an idiot.Quote:
Originally Posted by Salem
If there is some programmer or compiler creator here that I've just insulted, this thread should take an interesting turn :-)
Of course, these artifacts from nonstandardized days shouldn't be forcibly removed from compilers, so we're being a bit unfair.
Actually, I'd say these people are MUCH smarter than me, and probably a bit smarter than you. They are squeezing seconds off of coding time, not running time.Quote:
Gotta be a real moron to believe that the number of characters your program occupies has anything to do with the performance of the code.
Take a look at this, for example [registration required].
http://www.topcoder.com/stat?c=probl...696&cr=8355516
The code is cryptic, but I don't think you nor I would solve the problem in 7 minutes.
I actually have found that using <?= and >?= makes my code more buggy, since I somtimes omit characters and then do assignments or other similiar dumb stuff.
How do you know maxx, rt, or tt aren't objects with the != and + operators overloaded for some reason? The maxx != rt + tt statement might actually do something useful, although I really can't find a good reason why he would do it with those operators (especially !=) since it isn't intuitive.Quote:
Originally Posted by Dae
If I recall correctly, a for statement that looks like this:
is basically the same as:Code:for (initializing statement; condition; expression)
statement
So really, the expression can be just about anything. Though usually used to increment the loop, here it could be used just to update the variable. Maybe rt and tt change during the loop, and the OP wants to make sure that maxx = rt + tt at the end of each cycle through the loop. If you wanted to produce all fibonacci numbers under n, you could use it:Code:initializing statment
while (condition)
{
statement;}
expression;
Code:#include <cstdlib>
#include <iostream>
using namespace std;
int main()
{
int oldFibo = 0;
int olderFibo = 0;
int n = 100;
for (int fibo = 1; fibo < n; fibo = oldFibo + olderFibo)
{
olderFibo = oldFibo;
oldFibo = fibo;
cout << fibo << endl;
}
system("pause");
return 0;
}
> They are squeezing seconds off of coding time, not running time.
Absolutely pathetic reason if you ask me.
The biggest cost in software is understanding what the other person wrote (or even your own code) months after the event when it doesn't work anymore or needs to be enhanced.
Ever looked at any of your old "smart" code and wondered what the hell you were thinking of at the time?
Every stupid little trick in the book which obfuscates the code in some way simply adds to the difficulty.
I suppose they still think the xor swap without a temp is a really neat idea.
That would be a very good point, lol, a little too late.. but very good point.Quote:
Originally Posted by Speedy5
However, you cant overload <?=, and that is what was in the code, and someone said it stands for !=, which is the only reason I used != in that code you quoted. ;)
You're right, it can be anything - as I said. However the condition statement is automatically considered to operate like an if statement, while the expression part does not. Hence if the OP was trying to check if maxx != tt + rt, he would have to use an if statement around it in the expression - as I exampled. Without the if statement (as it is in the OP's code) it does not make sense to be the != operator, as we now know according to SilentStrike.Quote:
Originally Posted by Decrypt