Click here to Skip to main content
15,896,063 members
Home / Discussions / C#
   

C#

 
GeneralRe: Incrementing and Decrementing - Just Trying to Understand Pin
Dave Kreskowiak28-Apr-13 4:48
mveDave Kreskowiak28-Apr-13 4:48 
GeneralRe: Incrementing and Decrementing - Just Trying to Understand Pin
harold aptroot28-Apr-13 1:47
harold aptroot28-Apr-13 1:47 
GeneralRe: Incrementing and Decrementing - Just Trying to Understand Pin
N8tiv28-Apr-13 2:00
N8tiv28-Apr-13 2:00 
GeneralRe: Incrementing and Decrementing - Just Trying to Understand Pin
harold aptroot28-Apr-13 2:23
harold aptroot28-Apr-13 2:23 
GeneralRe: Incrementing and Decrementing - Just Trying to Understand Pin
N8tiv28-Apr-13 2:35
N8tiv28-Apr-13 2:35 
GeneralRe: Incrementing and Decrementing - Just Trying to Understand Pin
N8tiv28-Apr-13 3:05
N8tiv28-Apr-13 3:05 
GeneralRe: Incrementing and Decrementing - Just Trying to Understand Pin
harold aptroot28-Apr-13 3:33
harold aptroot28-Apr-13 3:33 
GeneralRe: Incrementing and Decrementing - Just Trying to Understand Pin
OriginalGriff28-Apr-13 3:44
mveOriginalGriff28-Apr-13 3:44 
GeneralRe: Incrementing and Decrementing - Just Trying to Understand Pin
harold aptroot28-Apr-13 3:54
harold aptroot28-Apr-13 3:54 
GeneralRe: Incrementing and Decrementing - Just Trying to Understand Pin
OriginalGriff28-Apr-13 4:15
mveOriginalGriff28-Apr-13 4:15 
GeneralRe: Incrementing and Decrementing - Just Trying to Understand Pin
harold aptroot28-Apr-13 4:19
harold aptroot28-Apr-13 4:19 
GeneralRe: Incrementing and Decrementing - Just Trying to Understand Pin
OriginalGriff28-Apr-13 4:26
mveOriginalGriff28-Apr-13 4:26 
GeneralRe: Incrementing and Decrementing - Just Trying to Understand Pin
harold aptroot28-Apr-13 4:31
harold aptroot28-Apr-13 4:31 
GeneralRe: Incrementing and Decrementing - Just Trying to Understand Pin
OriginalGriff28-Apr-13 4:46
mveOriginalGriff28-Apr-13 4:46 
GeneralRe: Incrementing and Decrementing - Just Trying to Understand Pin
harold aptroot28-Apr-13 4:59
harold aptroot28-Apr-13 4:59 
GeneralRe: Incrementing and Decrementing - Just Trying to Understand Pin
OriginalGriff28-Apr-13 5:08
mveOriginalGriff28-Apr-13 5:08 
GeneralRe: Incrementing and Decrementing - Just Trying to Understand Pin
Kenneth Haugland28-Apr-13 5:21
mvaKenneth Haugland28-Apr-13 5:21 
GeneralRe: Incrementing and Decrementing - Just Trying to Understand Pin
OriginalGriff28-Apr-13 5:25
mveOriginalGriff28-Apr-13 5:25 
GeneralRe: Incrementing and Decrementing - Just Trying to Understand Pin
Kenneth Haugland28-Apr-13 5:34
mvaKenneth Haugland28-Apr-13 5:34 
GeneralRe: Incrementing and Decrementing - Just Trying to Understand Pin
OriginalGriff28-Apr-13 5:41
mveOriginalGriff28-Apr-13 5:41 
GeneralRe: Incrementing and Decrementing - Just Trying to Understand Pin
Kenneth Haugland28-Apr-13 6:14
mvaKenneth Haugland28-Apr-13 6:14 
GeneralRe: Incrementing and Decrementing - Just Trying to Understand Pin
harold aptroot28-Apr-13 5:28
harold aptroot28-Apr-13 5:28 
GeneralRe: Incrementing and Decrementing - Just Trying to Understand Pin
Kenneth Haugland28-Apr-13 5:34
mvaKenneth Haugland28-Apr-13 5:34 
GeneralRe: Incrementing and Decrementing - Just Trying to Understand Pin
N8tiv28-Apr-13 21:33
N8tiv28-Apr-13 21:33 
GeneralRe: Incrementing and Decrementing - Just Trying to Understand Pin
Keld Ølykke28-Apr-13 20:34
Keld Ølykke28-Apr-13 20:34 
Hi,

Sometimes a simple description can be very hard to grasp - especially if the simple description tries to abstract the details away.
In such cases I find it rewarding simply to dig a bit deeper...

Here goes the details:
.entrypoint
// Code size       51 (0x33)
.maxstack  3
.locals init ([0] int32 x,
         [1] int32 y,
         [2] int32 z)
IL_0000:  nop             // evaluation stack is empty        []
// int x = 10;
IL_0001:  ldc.i4.s   10       // push 10 onto stack           [10]
IL_0003:  stloc.0         // pop 10 into x            []
// int y = 100;
IL_0004:  ldc.i4.s   100      // push 100 onto stack          [100]
IL_0006:  stloc.1         // pop 100 into y           []
// int z = y-- + x;
IL_0007:  ldloc.1         // push y onto stack            [100]
IL_0008:  dup             // copy top stack value onto stack  [100,100]
IL_0009:  ldc.i4.1            // push 1 onto stack            [1,100,100]
IL_000a:  sub             // y--                              [99,100]
IL_000b:  stloc.1         // pop 99 into y            [100]
IL_000c:  ldloc.0         // push x onto stack            [10,100]
IL_000d:  add             // + x                              [110]
IL_000e:  stloc.2         // pop 110 into z           []


If instruction, stack and arithmic unit are alien terms to you, then above might be a bit tough. It is a window into a lower layer of code. The C# compiler outputs this in binary form as your assembly/executable. IL means Intermediate Language and it can be executed by a Virtual Machine aka a program. The idea is to simulate the arithmic unit of a cpu, so above code is also a window into history.
-- and ++ are special language features that comes nearly for free because of the (virtual) machine architecture.

I produced above from your code example by running IL Disassembly from Microsft .Net.

Kind Regards,

Keld Ølykke

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.