473,388 Members | 1,298 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

Questions of .NET and managed coding

ax
"The benefits of running code in the managed environment of the CLR are
legion. For starters, as the JIT compiler converts CIL instructions into
native code, it enacts a code verification process that ensures the code is
type safe."

What does it mean by "type safe" here? Please give example about what
non-type-safe operations that native code can cause?

"You can't cast a type to something it's not because that operation isn't
type safe."

What does it mean by "cast a type to something it's not"?

"And you can't call a method with a malformed stack frame because the CLR
simply won't allow it to happen."

What's "a malformed stack frame"?

Thanks in advance!

Nov 17 '05 #1
1 846
ax wrote:
"The benefits of running code in the managed environment of the CLR are
legion. For starters, as the JIT compiler converts CIL instructions into
native code, it enacts a code verification process that ensures the code is
type safe."

What does it mean by "type safe" here? Please give example about what
non-type-safe operations that native code can cause?
compile in release mode:

#include "stdafx.h"

class Class1 {
int local1;
};
class Class2 {
public:
int local1;
char local2;
};
int _tmain()
{
Class1 class1;
int test = 0;
Class2* pClass2 = reinterpret_cast<Class2*>(&class1);
pClass2->local2 = 'd';
printf("%d \n", &class1);
//note that &test == &pClass2->local2
printf("%d \n", &test);
printf("%d \n", &pClass2->local2);
//oops, we just set 'test' to 100, this is probably not exactly what we
//wanted,
//however it will compile and run just fine, possibly causing errors
//that are hard to track down
printf("%d \n", test);
return 0;
}

however, you can use reinterpret_cast on __gc pointers as well! There's
a verifiable switch in the compiler (at least with whidbey) and (without
testing) I assume you wouldn't be able to compile things with that
switch enabled (or when using c# (without the unsafe switch))

If you check the resulting executable with peverify, it will tell you
that the code is not verifiable.
It also has implications for "code access security" which you best look
up in the msdn library.

"You can't cast a type to something it's not because that operation isn't
type safe."

What does it mean by "cast a type to something it's not"?

"And you can't call a method with a malformed stack frame because the CLR
simply won't allow it to happen."

What's "a malformed stack frame"?


I'm not entirely sure what they mean by that, the two things i can think
of are:
1.
calling a function via a function pointer that has a different signature
than the function you're calling.
So you can call methods with different paramters than the function expects.
With managed code you would use delegates instead which are strongly typed

2. a buffer underrun can cause the stack to be overwritten which can
lead to serious security problems.
With pure managed code, buffer over-/underruns shouldn't happen at all.

hth
--
Ben
http://bschwehn.de
Nov 17 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

54
by: Spammay Blockay | last post by:
I've been tasked with doing technical interviews at my company, and I have generally ask a range of OO, Java, and "good programming technique" concepts. However, one of my favorite exercises I...
7
by: Steven O. | last post by:
I am basically a hobbyist programmer, at the moment doing a little work experimenting with some AI stuff. I learned C++, and then tried to teach myself MFC using MS Visual C++ 6.0. I swore off of...
0
by: Flora Salim | last post by:
1. Does Visual C++.NET (managed environment) has much to offer than Visual C++ 6 (unmanaged) in terms of performance and stability? The thing that bother me is whether .NET takes much more disk...
8
by: Chun Wang | last post by:
1. When writing genric classes or methods, can I use specifc type (instead of generic type) as type parameter? For example: pulic class MyStack<T, int> { ..... }
1
by: Eric Twietmeyer | last post by:
Hello, I'm starting to investigate cs, managed c++ and interoperating with a very large unmanaged code base. We are going to use Windows Forms (written in cs) to replace our old fashioned GUI. ...
6
by: Teresa | last post by:
1) If I do want to keep an object alive throughout the live of an application, how can I ensure that the GC doesn't clean it up? 2a) How do I determine if an object is a managed or an unmanged...
8
by: Old VB6 Guy | last post by:
First of all, sorry if crossposting bothers you -- I don't normally do it, but both of these groups seem relavant to my questions. Alright, the time has finally come to make an investment in time...
87
by: Robert Seacord | last post by:
The SEI has published CMU/SEI-2006-TR-006 "Specifications for Managed Strings" and released a "proof-of-concept" implementation of the managed string library. The specification, source code for...
4
by: kimberly.walker | last post by:
Im very new to coding in C++ so use to coding in C#. My question is how to pass some values (string) from unmanaged code to managed code. I have two source files on a win32 console application one...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.