|
SomeFunc(i+1)
is NOT the same as
SomeFunc(++i)
because in the first case, you do NOT modify the value of i .
I think you missed that, as the argument degraded over time...
It started
i = i + 1;
and
i++;
or
++i;
all of which will modify the value of i
Marriage slows down your coding, a baby slows it down even more!
|
|
|
|
|
Can u also tell how did ur computer teacher
said it was fast .
(There is always have a question HOW ?)
Vikas Amin
Embin Technology
Bombay
vikas.amin@embin.com
|
|
|
|
|
It was about ++ uses inc instruction...
- NS -
|
|
|
|
|
Yeh ur absolutely right there is a INC
machine instruction but unfortunalty
our vc++ compiler dont use it .
Might be it is not a part of 486 instructin set
or we dont know how make the compiler use it .
Vikas Amin
Embin Technology
Bombay
vikas.amin@embin.com
-- modified at 6:34 Wednesday 28th December, 2005
|
|
|
|
|
in x86 instruction set there are 2 ways of incrementing a value
say
mov ax,[varname]<br />
add ax,1<br />
mov [varname],ax
or
mov ax,[varname]<br />
inc ax <========= adding a value one to the var, this way it is faster than add instruction<br />
move [varname],ax
this generation of instruction will be dependent on compiler and compiler settings (debug, release or optimised, etc)
in this case the VC compiler is generating same instructions for both cases.
<hr<span style="color:gray;size:15px;">-Prakash
-Prakash
|
|
|
|
|
NS17 wrote: But I studied in my computer classes that i++ is faster than = i+1.
any decent compiler will treat i++ and i=i+1 as identical, when optimizing.
Cleek | Image Toolkits | Thumbnail maker
|
|
|
|
|
There are a couple of cases to look at here.
First, if the variable 'i ' is an integral type*, most compilers will optimize them to the same machine language. In a release compile, that might be a single 'increment' instruction, if the variable is currently held in a register. The example you found has the variable stored on the stack. * An integral type includes char , int , short , and long .
In the general case, where i is an object from an arbitrary class, the answer depends upon the implementation.
The code for i++ calls the copy constructor followed by the increment operator for the class.
The code for i = i + 1 calls the addition operator and the assignment operator for the class. Depending upon the definition of the addition operator, an additional call to the copy constructor may be required.
In practical terms, I wouldn't worry about which was more efficient. Most of the time, you'll choose the operation based upon which one makes the code more readable. In a simple for() loop, the increment form i++ is preferable. If this is part of logic that can change the variable by steps other than 1, then the assignment form i = i + 1 is more readable.
Software Zen: delete this; // <a href="http://www.codeproject.com/script/profile/whos_who.asp?msg=1307432&id=10338#xx1307432xx" rel="nofollow">Fold With Us!</a>[<a href="http://www.codeproject.com/script/profile/whos_who.asp?msg=1307432&id=10338#xx1307432xx" target="_blank" rel="nofollow" title="New Window">^</a>]
|
|
|
|
|
Hi I have a problem.....
Actually i wrote a code which runs in service and hides in tray icon when minimized or closed...
When iam testing it by executing, its working , after when i restart the system to make run in service..
It is visible in service ,But No tray icon is Visible
If i keep any message Box in OnCreate() function ,
Then it's Working ...
Please help me...............
Some one told me that i have to Reset the tray icon for every one minute.
how can it been done...
or any other Answer
Thanks
|
|
|
|
|
|
any other way please help me your views and xperience not the reference
Thanks in Advance
|
|
|
|
|
Why are you creating a service with a UI? Before even trying to track this down, are you sure this is what you want? A true service should run without any need for a user context or interface.
"Take only what you need and leave the land as you found it." - Native American Proverb
|
|
|
|
|
I used VC++ CImage class to display a transparent PNG picture.
But its background that should be transparent, display a semi-transparent white layer.
How could I fix these problem ?
|
|
|
|
|
It might sound strange but as far as i know
integer is 2 bytes . But in my code i declared
such a simple array
int arr[2][3][3] = {
{
{2000, 4,1},
{7, 8,1},
{3, 9,1}
},
{
{71, 61,11},
{31, 41,11},
{51, 91,11}
}
};
Why the hell do it store a integer as 4 byte in VC++
it a simple console app.
Vikas Amin
Embin Technology
Bombay
vikas.amin@embin.com
|
|
|
|
|
In Win32, sizeof(int) is 4 bytes.
|
|
|
|
|
|
size of int is OS dependent
never say die
|
|
|
|
|
actually, it is not OS dependent, but implementation dependent. standard states that sizeof(int) >= sizeof(short), and short is at least 16 bits. so, for different compilers, sizeof(int) can be different even on the same OS.
|
|
|
|
|
and they are also processor dependent but not too much though.
<hr<span style="color:gray;size:15px;">-Prakash
-Prakash
|
|
|
|
|
Processor dependent ?????
Vikas Amin
Embin Technology
Bombay
vikas.amin@embin.com
|
|
|
|
|
Well to understand this u need to know how softwares are dependent on hardware (processor)
generally the integer size is the size of word size of the processor, for 80386 onwards the word size is 32 bit and hence the integer size in most of the OS on Intel machine is 32bit.
Why the size of integer varies from compiler to compiler/OS 2 OS, because integer is the most used datatype and transfering a 32bit of data from the memory to processor is more efficient than other sized data.
<hr<span style="color:gray;size:15px;">-Prakash
-Prakash
|
|
|
|
|
vikas amin wrote: Processor dependent ?????
In continuation with Mr. Prakash.. if you see := sizeof(long)==sizeof(int) in windows enviornment
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
|
|
|
|
|
Zdeslav Vojkovic wrote: ...sizeof(int) can be different even on the same OS.
Do you have a valid example of such? I've never seen an int that varied in size on the same machine.
"Take only what you need and leave the land as you found it." - Native American Proverb
|
|
|
|
|
This goes back a bit in time, but...
In Microsoft C 6.0 (MS-DOS era), an int was 16 bits. Watcom C 9.0, on the same machine, made an int to be 32 bits. The Microsoft target in this case was 16-bit real-mode MS-DOS while the Watcom target was 32-bit protected mode MS-DOS.
Software Zen: delete this; // <a href="http://www.codeproject.com/script/profile/whos_who.asp?msg=1307432&id=10338#xx1307432xx" rel="nofollow">Fold With Us!</a>[<a href="http://www.codeproject.com/script/profile/whos_who.asp?msg=1307432&id=10338#xx1307432xx" target="_blank" rel="nofollow" title="New Window">^</a>]
|
|
|
|
|
But was it a true 32-bit int ? That's like saying we have a 64-bit int today, but only because Microsoft's compiler mashes two 32-bit int s together, simulating a bigger one.
"Take only what you need and leave the land as you found it." - Native American Proverb
|
|
|
|
|
Actually it was. The 80386 processors and their descendents included direct 32-bit arithmetic and pointer support. The Watcom compiler supported protected mode execution with a flat memory model for a variety of DOS extenders. A "DOS extender" basically provided an execution environment for a protected mode application in the MS-DOS environment.
DavidCrow wrote: Microsoft's compiler mashes two 32-bit ints together
Hmm. Is that still the case? I was under the impression that __int64 support since VS.NET 2002 was provided directly by native instructions.
Software Zen: delete this; // <a href="http://www.codeproject.com/script/profile/whos_who.asp?msg=1307432&id=10338#xx1307432xx" rel="nofollow">Fold With Us!</a>[<a href="http://www.codeproject.com/script/profile/whos_who.asp?msg=1307432&id=10338#xx1307432xx" target="_blank" rel="nofollow" title="New Window">^</a>]
|
|
|
|