Click here to Skip to main content
15,892,005 members
Home / Discussions / C#
   

C#

 
GeneralRe: Assigning an icon to Windows Application Pin
Luc Pattyn10-Dec-08 5:09
sitebuilderLuc Pattyn10-Dec-08 5:09 
GeneralRe: Assigning an icon to Windows Application Pin
Pr@teek B@h!10-Dec-08 5:34
Pr@teek B@h!10-Dec-08 5:34 
GeneralRe: Assigning an icon to Windows Application Pin
Luc Pattyn10-Dec-08 6:21
sitebuilderLuc Pattyn10-Dec-08 6:21 
GeneralRe: Assigning an icon to Windows Application Pin
Pr@teek B@h!10-Dec-08 7:37
Pr@teek B@h!10-Dec-08 7:37 
Questioncombo box Pin
kirandilip10-Dec-08 4:14
kirandilip10-Dec-08 4:14 
AnswerRe: combo box Pin
EliottA10-Dec-08 4:25
EliottA10-Dec-08 4:25 
AnswerRe: combo box Pin
Priya Prk10-Dec-08 8:50
Priya Prk10-Dec-08 8:50 
QuestionFrom ILGenerator and emit to fixed? [modified + solution] Pin
Ravadre10-Dec-08 4:12
Ravadre10-Dec-08 4:12 
Hi,
Recently I'm working on small compiler for fun (or actually still thinking about it's main features and implementing basic syntax) and I've ran into strange problem. Something that I thought would be easy seem not to be that easy Smile | :) . What is troubling my mind, is that construction:

int[] b = new int [100];
fixed (int* p = b)
{
   int* z = p;
   for (int i = 0; i < 100; ++i)
   {
     *z = i;
     z++;
   }
}


Such code when compiled and disassembled produces such code:
.locals init ([0] int32[] b,
             [1] int32 i,
             [2] int32& pinned p,
             [3] int32* z,
             [4] bool CS$4$0000,
             [5] int32[] CS$0$0001)
[...].IL_0031:  ldloc.s    CS$0$0001
IL_0033:  ldc.i4.0
IL_0034:  ldelema    [mscorlib]System.Int32
IL_0039:  stloc.2


This code, from what I understand after searching information in MSDN and few other articles, pins table b (table [5] is the same as b) by pointing to it's first element with p pointer.
I've tried to produce such code using ILGenerator, but I have no idea how to declare local variable of type int& (managed pointer), I guess I can declare only int* pointers, now the main question is, will above code work if I change [2] int32& pinned p to [2] int* pinned p. If yes, why compiler uses this type, not just int* pointers, if no - how I can generate such code using code emit?
I've made small test, disassembled code compiled with csc, changed pointer from int& to int* and yes, it works, but I can't prove anything with that, because GC had no reason to move the table in memory and I can't force him to try that, so that answered nothing except that I know such construction would be legal.


[Solution]

For future use hehe, I'll post solution I've come by accident, and it does seem to work:
ilGen.DeclareLocal(Type.GetType("System.Int32&"), true);

Although it's impossible to "do" anything with this type in code, it seems that it is possible to emit it to assembly (after all Smile | :) ).

modified on Wednesday, December 10, 2008 12:23 PM

GeneralRe: From ILGenerator and emit to fixed? Pin
Luc Pattyn10-Dec-08 5:07
sitebuilderLuc Pattyn10-Dec-08 5:07 
GeneralRe: From ILGenerator and emit to fixed? Pin
Ravadre10-Dec-08 5:49
Ravadre10-Dec-08 5:49 
AnswerRe: From ILGenerator and emit to fixed? Pin
Simon P Stevens10-Dec-08 5:11
Simon P Stevens10-Dec-08 5:11 
GeneralRe: From ILGenerator and emit to fixed? Pin
Ravadre10-Dec-08 5:47
Ravadre10-Dec-08 5:47 
GeneralRe: From ILGenerator and emit to fixed? Pin
Simon P Stevens10-Dec-08 5:55
Simon P Stevens10-Dec-08 5:55 
GeneralRe: From ILGenerator and emit to fixed? Pin
Ravadre10-Dec-08 6:01
Ravadre10-Dec-08 6:01 
QuestionWidows helper and CHM Pin
half-life10-Dec-08 4:01
half-life10-Dec-08 4:01 
AnswerRe: Widows helper and CHM Pin
EliottA10-Dec-08 4:28
EliottA10-Dec-08 4:28 
GeneralRe: Widows helper and CHM Pin
half-life10-Dec-08 6:55
half-life10-Dec-08 6:55 
GeneralRe: Widows helper and CHM Pin
EliottA10-Dec-08 6:57
EliottA10-Dec-08 6:57 
QuestionFormat of decimal numbers [modified] Pin
Diving Flo10-Dec-08 2:00
Diving Flo10-Dec-08 2:00 
AnswerRe: Format of decimal numbers Pin
Mirko198010-Dec-08 2:24
Mirko198010-Dec-08 2:24 
GeneralRe: Format of decimal numbers Pin
Diving Flo10-Dec-08 2:35
Diving Flo10-Dec-08 2:35 
Questionany API to make flash file conversion? Pin
George_George10-Dec-08 1:52
George_George10-Dec-08 1:52 
AnswerRe: any API to make flash file conversion? Pin
Lev Danielyan10-Dec-08 2:20
Lev Danielyan10-Dec-08 2:20 
GeneralRe: any API to make flash file conversion? Pin
George_George10-Dec-08 2:23
George_George10-Dec-08 2:23 
GeneralRe: any API to make flash file conversion? Pin
Lev Danielyan10-Dec-08 2:28
Lev Danielyan10-Dec-08 2:28 

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.