Native C#

J

Jack

I wonder C# can produce native win32 code.
I have read several articles about C#,
and I found it very useful because you don't have to remember all the
"starting" syntax and you still have a decent garbage collector and you
might use pointers too as needed. However I am worrying about if it could
produce native code. I suspect I'll have to use the .NET Framework. Is that
right? Any comments are welcome!
Thanks
Jack
 
M

Michael Nemtsev

Hello Jack,

See unsafe keyword in MSDN http://msdn2.microsoft.com/en-us/library/chfa2zb8.aspx
Take into account that CLR don't verify unsafe code

J> I wonder C# can produce native win32 code.
J> I have read several articles about C#,
J> and I found it very useful because you don't have to remember all the
J> "starting" syntax and you still have a decent garbage collector and
J> you
J> might use pointers too as needed. However I am worrying about if it
J> could
J> produce native code. I suspect I'll have to use the .NET Framework.
J> Is that
J> right? Any comments are welcome!
J> Thanks
J> Jack
---
WBR,
Michael Nemtsev :: blog: http://spaces.msn.com/laflour

"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsch
 
F

Frank Rizzo

Jack said:
I wonder C# can produce native win32 code.
I have read several articles about C#,
and I found it very useful because you don't have to remember all the
"starting" syntax and you still have a decent garbage collector and you
might use pointers too as needed. However I am worrying about if it could
produce native code. I suspect I'll have to use the .NET Framework. Is that
right? Any comments are welcome!
Thanks
Jack
I am afraid you are stuck with the .NET framework and managed code. No
native code with c#, period.
 
G

Guest

You can specify /unsafe compiler option. In this case CLR don't verify you
app, that leeds to some limitations, and allows use unmanaged constructions
I am afraid you are stuck with the .NET framework and managed code. No
native code with c#, period.

--
WBR,
Michael Nemtsev :: blog: http://spaces.msn.com/laflour

"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsche
 
W

Willy Denoyette [MVP]

Unsafe != native code, and that's what the OP is asking about.

Willy.

| You can specify /unsafe compiler option. In this case CLR don't verify
you
| app, that leeds to some limitations, and allows use unmanaged
constructions
|
| > I am afraid you are stuck with the .NET framework and managed code. No
| > native code with c#, period.
|
| --
| WBR,
| Michael Nemtsev :: blog: http://spaces.msn.com/laflour
|
| "At times one remains faithful to a cause only because its opponents do
not
| cease to be insipid." (c) Friedrich Nietzsche
|
 
G

Guest

yep,
just missed the point of original question
Unsafe != native code, and that's what the OP is asking about.

Willy.

| You can specify /unsafe compiler option. In this case CLR don't verify
you
| app, that leeds to some limitations, and allows use unmanaged
constructions
|
| > I am afraid you are stuck with the .NET framework and managed code. No
| > native code with c#, period.

--
WBR,
Michael Nemtsev :: blog: http://spaces.msn.com/laflour

"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsche
 
J

james.curran

Well, you can't get completely to native code, because C# assumes
garbage collection, so at the minimum, you would need some garbage
collecting framework (like the CLR) between the code and the Win32 API.

However, if you accept that, not only CAN it be done, it IS being done.
It's just done in two steps. At compile time, C# is translated in IL,
and then at run time, IL is translated into native code. Hence C# has
produced native code. There is a way to do both steps at compile time,
but overall, it's best to let the final step be done on a machine that
actually going to run the code. (Presently, and by necessity if you
precompile, the native code produced will be tuned so that it might run
better on a Pentium, but will nevertheless run on a 80386. However, in
the future, we should be getting JITters that will target exclusively
the chip type that it is being run on)
 
A

Andre Kaufmann

Jack said:
I wonder C# can produce native win32 code.

Why not ? But the C# compiler shipped with the .NET framework cannot do
that (yet). Currently you can use NGen.exe to compile a native managed
executable out of any C# assembly, but you are bound to the .NET
framework anyways. You only save delay caused by the JIT compilation on
startup.
I have read several articles about C#,
and I found it very useful because you don't have to remember all the
"starting" syntax and you still have a decent garbage collector and you
might use pointers too as needed. However I am worrying about if it could
produce native code. I suspect I'll have to use the .NET Framework. Is that
right? Any comments are welcome!

Microsoft research has used a native C# compiler, called Bartok to
compile the research OS Singularity.

http://research.microsoft.com/act

IIRC this compiler uses a small compact runtime, not the .NET framework
itself. Perhaps it will be available and part of VStudio, when the
compiler framework Phoenix is released which IMHO will be the basis of a
native C# compiler.
Thanks
Jack

Andre
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top