^ I agree... but please don't say 'natural'... after another thread I started, I plan on completely deleting the word 'natural' from my vocabulary...
a++
++a
a = a + 1
a = 1 + a
never uses them
^ I agree... but please don't say 'natural'... after another thread I started, I plan on completely deleting the word 'natural' from my vocabulary...
Join is in our Unofficial Cprog IRC channel
Server: irc.phoenixradio.org
Channel: #Tech
Team Cprog Folding@Home: Team #43476
Download it Here
Detailed Stats Here
More Detailed Stats
52 Members so far, are YOU a member?
Current team score: 1223226 (ranked 374 of 45152)
The CBoard team is doing better than 99.16% of the other teams
Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)
Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT
How about:
a += 1;
I'm tending to use that more and more often. It just looks better and clearer.
oookkk....Originally posted by Speedy5
How about:
a += 1;
I'm tending to use that more and more often. It just looks better and clearer.
Do not make direct eye contact with me.
Unless I am using the return value for something (which is fairly rare) forcing the issue, I prefer to use ++a.
The word rap as it applies to music is the result of a peculiar phonological rule which has stripped the word of its initial voiceless velar stop.
Yes, but the only difference is a single subtraction operation done by the processor. If you need to optimize things like that, do what Sebastiani said and use asm.Originally posted by Prelude
>Indeed.
I think you missed the point. A well known micro-optimization technique is to invert the loop, starting from the end and decrementing. This is on the assumption that some machines have a special instruction for decrementing and comparing with zero and a reversed loop is a good hint to the compiler to use those instructions.
are you insane? how doesOriginally posted by Speedy5
How about:
a += 1;
I'm tending to use that more and more often. It just looks better and clearer.look better thanCode:a += 1;i just don't get it...Code:a++; //or ++a;
Join is in our Unofficial Cprog IRC channel
Server: irc.phoenixradio.org
Channel: #Tech
Team Cprog Folding@Home: Team #43476
Download it Here
Detailed Stats Here
More Detailed Stats
52 Members so far, are YOU a member?
Current team score: 1223226 (ranked 374 of 45152)
The CBoard team is doing better than 99.16% of the other teams
Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)
Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT
I use that only when it's a number other an 1.Originally posted by Speedy5
How about:
a += 1;
I'm tending to use that more and more often. It just looks better and clearer.
For just an incremment of one I usually use a++ out of habit, but sometimes just to be "a little crazy" about things I will use ++a hehe.
I wonder if there will ever be a language based on C++ called C+=2
Hey, I made that joke a few weeks ago :P
I do tend to use ++a (or --a) unless I need the old value. Although any good optimizing compiler should make no distinction, ++a is:
* As readable as a++
* Never worse in performance than a++ and sometimes better
I agree, increment/decrement is not the place to look at optimizing, but this is not your typical optimization, because there is no benefit from a++ if you don't need the old value. Optimization is all about making decisions based on tradeoffs. For example, do you want a fast program or a small one? Do you want to take advantage of processor-specific features that might slow your program down on other systems? Do you want to keep your classes very uncoupled, making code changes easier and bugs rarer, or do you need the added speed that tighter coupling can provide?
In this case, if there is only one side of the story -- if ++a is always as good and possibly better (at least in cases where ++ has the typical meaning), then I think ++a is the way to go.
You ever try a pink golf ball, Wally? Why, the wind shear on a pink ball alone can take the head clean off a 90 pound midget at 300 yards.
a++ is much faster than ++a because its easier for the 'a' to push the ++ forward in the program rather than pull it. dont you agree that pushing is easier than pulling?
pulling is much easier when your in practise
"Assumptions are the mother of all **** ups!"
According to the discussion of whether ++a is faster than a++ I have made a few tests. i compiled the test program below (without optimizations) and got the following results:
EDIT:
Old code, see next page for updated test
As you can see, not much differs from them. They have the same instructions run, only in a different order. My conclusion from this is they are both running at the same speed. If someone else have anything to add, please do.
EDIT: Another observation. In a = a++ there is this line:
This could be optimized away, thus making a=a++ faster.Code:mov eax, DWORD PTR _a$[ebp] mov DWORD PTR _a$[ebp], eax
Last edited by Magos; 11-29-2003 at 11:31 AM.
MagosX.com
Give a man a fish and you feed him for a day.
Teach a man to fish and you feed him for a lifetime.
>This could be optimized away, thus making a=a++ faster.
Why would you want to optimize undefined behavior?
My best code is written with the delete key.
> Why would you want to optimize undefined behavior?
Well would you want it slow... There's no fun in that.
The word rap as it applies to music is the result of a peculiar phonological rule which has stripped the word of its initial voiceless velar stop.