Click here to Skip to main content
15,887,291 members
Home / Discussions / C#
   

C#

 
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
GeneralRe: Incrementing and Decrementing - Just Trying to Understand Pin
N8tiv28-Apr-13 22:11
N8tiv28-Apr-13 22:11 
GeneralRe: Incrementing and Decrementing - Just Trying to Understand Pin
harold aptroot28-Apr-13 22:20
harold aptroot28-Apr-13 22:20 
GeneralRe: Incrementing and Decrementing - Just Trying to Understand Pin
N8tiv28-Apr-13 22:35
N8tiv28-Apr-13 22:35 
GeneralRe: Incrementing and Decrementing - Just Trying to Understand Pin
harold aptroot28-Apr-13 22:42
harold aptroot28-Apr-13 22:42 
GeneralRe: Incrementing and Decrementing - Just Trying to Understand Pin
N8tiv28-Apr-13 22:54
N8tiv28-Apr-13 22:54 
GeneralRe: Incrementing and Decrementing - Just Trying to Understand Pin
OriginalGriff28-Apr-13 23:39
mveOriginalGriff28-Apr-13 23:39 
GeneralRe: Incrementing and Decrementing - Just Trying to Understand Pin
N8tiv28-Apr-13 23:47
N8tiv28-Apr-13 23:47 
GeneralRe: Incrementing and Decrementing - Just Trying to Understand Pin
OriginalGriff29-Apr-13 0:33
mveOriginalGriff29-Apr-13 0:33 
GeneralRe: Incrementing and Decrementing - Just Trying to Understand Pin
N8tiv30-Apr-13 19:04
N8tiv30-Apr-13 19:04 
GeneralRe: Incrementing and Decrementing - Just Trying to Understand Pin
OriginalGriff30-Apr-13 21:57
mveOriginalGriff30-Apr-13 21:57 
GeneralRe: Incrementing and Decrementing - Just Trying to Understand Pin
N8tiv30-Apr-13 23:02
N8tiv30-Apr-13 23:02 
GeneralRe: Incrementing and Decrementing - Just Trying to Understand Pin
OriginalGriff30-Apr-13 23:36
mveOriginalGriff30-Apr-13 23:36 
GeneralRe: Incrementing and Decrementing - Just Trying to Understand Pin
N8tiv4-May-13 22:31
N8tiv4-May-13 22:31 
GeneralRe: Incrementing and Decrementing - Just Trying to Understand Pin
OriginalGriff4-May-13 22:50
mveOriginalGriff4-May-13 22:50 
GeneralRe: Incrementing and Decrementing - Just Trying to Understand Pin
N8tiv4-May-13 23:02
N8tiv4-May-13 23:02 
GeneralRe: Incrementing and Decrementing - Just Trying to Understand Pin
OriginalGriff4-May-13 23:14
mveOriginalGriff4-May-13 23:14 
GeneralRe: Incrementing and Decrementing - Just Trying to Understand Pin
N8tiv4-May-13 23:48
N8tiv4-May-13 23:48 

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.