.NETGURU
Questions of .NET and managed coding
Messages   Related Types
This message was discovered on microsoft.public.dotnet.languages.vc.

Post a new message to this list...

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!

Reply to this message...
 
    
Ben Schwehn
ax wrote:
[Original message clipped]

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.

[Original message clipped]

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
Reply to this message...
 
 




ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
Ad


Need Dot Net Interview Questions?
Ask ExamGuru, Inc. for advice and help on Passing .Net Interviews
.Net Projects
Best-of-breed application framework for .NET projects, developed by ExamGuru, Inc. and ExamGuru IT
Free .net Help
Commission ExamGuru, Inc. and his team for your next bespoke software project
FogBUGZ
The only bug tracking system carefully crafted with one goal in mind: helping teams create great software.
Awesome Tools
If you don't know about these, you're missing out... IT Certification Questions
IT Interview Questions
Free Oracle 10g Training
MCSE Boortcamp
Cisco Study Guides
Cheap Study Guides
Exact Questions
Dot Net Interview Questions
Oracle OCP
Cheap Travel
Designer Perfumes - Wholesale Prices
Free Programming Tutorials
 
ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
 Copyright © ExamGuru, Inc. 2001-2006
Contact Us - Terms of Use - Privacy Policy - www.dot-net-guru.com - www.examguru.net - www.oraclesource.net - www.itinterviews.net - www.examguru.net/ITCertification