In C, Suppose you want to declare a variable, and say you need some initial numberic value in it, and then you are going to use that variable later, like:
int var1;var1=0;var1=var1+7;
int var1=0;var1=var1+7;
8/30/2005 6:03:00 PM
for a good compiler - same
8/30/2005 6:09:23 PM
I don't know for sure, but I would guess they compile to the same thing.
8/30/2005 6:09:36 PM
Write your code so it is as readable as possible, document well, and get a good compiler.
8/30/2005 6:11:00 PM
trying to make optimizations like these are idiotic unless your time is not very valuable. Most of your time should be focused on design and algorithmic optimizations.
8/30/2005 8:01:42 PM
yea, this question is only relevant if you're writing assembly - and even then, i'd hope the assembler would assemble it the same either way.
8/30/2005 8:15:05 PM
Both methods will reduce to something like this (probably exactly like this, at least for msvc++):mov dword ptr [var1],0 mov eax,dword ptr [var1] add eax,7 mov dword ptr [var1],eax^^ While that is probably true for plain old C, in C++ you have to be very careful with default versus copy constructors. For example, if you have a class that is expensive to construct but lightweight in terms of copy construction and assignment, then tracking down the places where you do:someClass obj;obj = obj2;and changing it to:someClass obj = obj2;could potentially give you huge performance wins.
8/30/2005 8:21:13 PM
FORTRAN bitches
8/30/2005 11:06:08 PM
int var1=0;var1+=7;[Edited on August 31, 2005 at 12:00 AM. Reason : the important stuff has been said, that's just how I'd write it]
8/30/2005 11:59:19 PM
int var1 = 7;damn
8/31/2005 10:49:23 AM
#define var1 7I win.
8/31/2005 12:56:15 PM
^ he wins
8/31/2005 2:42:52 PM
7;i win
8/31/2005 10:52:18 PM