The curley bracket!

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • AricC
    Recognized Expert Top Contributor
    • Oct 2006
    • 1885

    #61
    Originally posted by Banfa
    Hmm only if you believe the poster of the original comment that ++i is more efficient than i++ because of a copy but there are many cases where there would be no need of a copy and many more where optimiser would come along and optimise away the inefficiency.

    I do not think the argument for ++i over i++ holds water.
    I didn't believe the argument in the first place, like I said even if there were a difference we would probably be talking mili/nano seconds.

    Comment

    • RedSon
      Recognized Expert Expert
      • Jan 2007
      • 4980

      #62
      INSANE all of you are INSANE! I'm not.

      Comment

      • stroken
        New Member
        • Mar 2007
        • 24

        #63
        Originally posted by AricC
        With the speeds of PC processing these days I wouldn't think this is a big factor. Do you any have proof?
        Most of the computers (more than 99%) are small, cheap embedded computers with limited memory and speed.

        In the case of ++ with a primitive type, it does not make a big difference, but you should use it for convention. (someday you will do ++ for your own class).

        Just imagine you have a class that stores a lot of information, say 1MB, create a copy of this will take much longer time than just sending a reference.

        I think some code will explain this better, in this simple example ++ should only increment index.

        Code:
        // prefix
        UrClass& UrClass::operator++() {
            ++index;
            return *this;
        }
        
        // postfix
        const UrClass UrClass::operator++() {
           UrClass temp(*this);
           ++*this;
           return temp;
        }
        Do you see the difference?

        Comment

        • stroken
          New Member
          • Mar 2007
          • 24

          #64
          Originally posted by AricC
          No I don't work for MS but tell me how ++ is that much faster than +=?
          Write a class, and overload the operators ++ (prefix and infix) and+= (or buy a good book and read), look at the code and figure it out.

          Comment

          Working...