Thread: <?= operator

  1. #16
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    I would imagine maxx would be used inside the loop.

  2. #17
    Deprecated Dae's Avatar
    Join Date
    Oct 2004
    Location
    Canada
    Posts
    1,034
    Quote Originally Posted by Thantos
    I would imagine maxx would be used inside the loop.
    Dae.IQ = Dae.IQ - 20;

    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?

    Code:
    for(int i = 0; i++ < limit; )
    {
      maxx != rt + tt;
    }
    Its not a condition, its just.. out there.. for what reason?

    Sorry I cant see any reason for why its there, other than none.
    Warning: Have doubt in anything I post.

    GCC 4.5, Boost 1.40, Code::Blocks 8.02, Ubuntu 9.10 010001000110000101100101

  3. #18
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    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.

  4. #19
    Deprecated Dae's Avatar
    Join Date
    Oct 2004
    Location
    Canada
    Posts
    1,034
    Quote Originally Posted by Thantos
    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.

    Code:
    for(int i = 0; i++ < limit; maxx != rt + tt)
    {
    ...
    }
    
    is equal to:
    
    for(int i = 0; i++ < limit; )
    {
      maxx != rt + tt;
    }
    Code:
    for(int i = 0; i++ < limit; maxx != rt + tt)
    {
    ...
    }
    
    is equal to:
    
    for(int i = 0; ; maxx != rt + tt)
    {
      if(!(i++ < limit))
        break;
    }
    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; if(maxx != rt + tt) break)
    {
    ...
    }
    
    is equal to:
    
    for(int i = 0; i++ < limit; )
    {
      if(maxx != rt + tt) 
        break;
    }
    Warning: Have doubt in anything I post.

    GCC 4.5, Boost 1.40, Code::Blocks 8.02, Ubuntu 9.10 010001000110000101100101

  5. #20
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    Who knows why they did it, its probably just a mistake they made, but really who cares?

  6. #21
    geek SilentStrike's Avatar
    Join Date
    Aug 2001
    Location
    NJ
    Posts
    1,141
    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.
    Last edited by SilentStrike; 09-25-2005 at 05:37 PM.
    Prove you can code in C++ or C# at TopCoder, referrer rrenaud
    Read my livejournal

  7. #22
    Deprecated Dae's Avatar
    Join Date
    Oct 2004
    Location
    Canada
    Posts
    1,034
    Quote Originally Posted by Thantos
    Who knows why they did it, its probably just a mistake they made, but really who cares?
    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.
    Warning: Have doubt in anything I post.

    GCC 4.5, Boost 1.40, Code::Blocks 8.02, Ubuntu 9.10 010001000110000101100101

  8. #23
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,656
    > 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?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  9. #24
    aoeuhtns
    Join Date
    Jul 2005
    Posts
    581
    Quote Originally Posted by Salem
    > 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.

    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.

  10. #25
    geek SilentStrike's Avatar
    Join Date
    Aug 2001
    Location
    NJ
    Posts
    1,141
    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.
    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.

    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.
    Prove you can code in C++ or C# at TopCoder, referrer rrenaud
    Read my livejournal

  11. #26
    Registered User
    Join Date
    Jan 2003
    Posts
    648
    Quote Originally Posted by Dae
    Sorry I cant see any reason for why its there, other than none.
    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.

  12. #27
    Moderately Rabid Decrypt's Avatar
    Join Date
    Feb 2005
    Location
    Milwaukee, WI, USA
    Posts
    300
    If I recall correctly, a for statement that looks like this:

    Code:
    for (initializing statement; condition; expression)
         statement
    is basically the same as:

    Code:
    initializing statment
    while (condition)
    {
    
    statement; expression;
    }
    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:
    #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;
    }
    There is a difference between tedious and difficult.

  13. #28
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,656
    > 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.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  14. #29
    Deprecated Dae's Avatar
    Join Date
    Oct 2004
    Location
    Canada
    Posts
    1,034
    Quote Originally Posted by Speedy5
    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.
    That would be a very good point, lol, a little too late.. but very good point.

    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.
    Warning: Have doubt in anything I post.

    GCC 4.5, Boost 1.40, Code::Blocks 8.02, Ubuntu 9.10 010001000110000101100101

  15. #30
    Deprecated Dae's Avatar
    Join Date
    Oct 2004
    Location
    Canada
    Posts
    1,034
    Quote Originally Posted by Decrypt
    If I recall correctly, a for statement that looks like this:

    Code:
    for (initializing statement; condition; expression)
         statement
    is basically the same as:

    Code:
    initializing statment
    while (condition)
    {
    
    statement; expression;
    }
    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]#include <cstdlib>
    #include <iostream>
    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.
    Warning: Have doubt in anything I post.

    GCC 4.5, Boost 1.40, Code::Blocks 8.02, Ubuntu 9.10 010001000110000101100101

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. unary operator overloading and classes
    By coletek in forum C++ Programming
    Replies: 9
    Last Post: 01-10-2009, 02:14 AM
  2. Smart pointer class
    By Elysia in forum C++ Programming
    Replies: 63
    Last Post: 11-03-2007, 07:05 AM
  3. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  4. Operator Overloading (Bug, or error in code?)
    By QuietWhistler in forum C++ Programming
    Replies: 2
    Last Post: 01-25-2006, 08:38 AM
  5. operator overloading and dynamic memory program
    By jlmac2001 in forum C++ Programming
    Replies: 3
    Last Post: 04-06-2003, 11:51 PM