Using /clr:safe and Native Types

G

Gary Nastrasio

If I compile with /clr:safe, which is exactly meant by saying I can't
use "Native Types" in my code? Is a native type something such as
float, short, or int?

Thanks,

Gary
 
J

Jochen Kalmbach [MVP]

Gary said:
If I compile with /clr:safe, which is exactly meant by saying I can't
use "Native Types" in my code? Is a native type something such as
float, short, or int?

No. AFAIK, this types will be mapped to System::Single, System::Int16
and System::Int32

--
Greetings
Jochen

My blog about Win32 and .NET
http://blog.kalmbachnet.de/
 
W

Willy Denoyette [MVP]

| If I compile with /clr:safe, which is exactly meant by saying I can't
| use "Native Types" in my code? Is a native type something such as
| float, short, or int?
|
| Thanks,
|
| Gary

No, native types are types like pointers (int* blabla) user defined native
types (class, struct...) C++ intrinsic types like wchar_t etc..
Primitive types like int, short, float, double ... are directly mapped to
the corresponding CLR types System::Int32, Int16, Float, Double ..


Willy.
 
C

Carl Daniel [VC++ MVP]

Willy said:
No, native types are types like pointers (int* blabla) user defined
native types (class, struct...) C++ intrinsic types like wchar_t etc..
Primitive types like int, short, float, double ... are directly
mapped to the corresponding CLR types System::Int32, Int16, Float,
Double ..

wchar_t maps to System::Char in managed C++, so it's fine for /clr:safe as
well as the other intrinsic types you mentioned.

-cd
 
W

Willy Denoyette [MVP]

"Carl Daniel [VC++ MVP]" <[email protected]>
wrote in message | Willy Denoyette [MVP] wrote:
| > | >> If I compile with /clr:safe, which is exactly meant by saying I can't
| >> use "Native Types" in my code? Is a native type something such as
| >> float, short, or int?
| >>
| >> Thanks,
| >>
| >> Gary
| >
| > No, native types are types like pointers (int* blabla) user defined
| > native types (class, struct...) C++ intrinsic types like wchar_t etc..
| > Primitive types like int, short, float, double ... are directly
| > mapped to the corresponding CLR types System::Int32, Int16, Float,
| > Double ..
|
| wchar_t maps to System::Char in managed C++, so it's fine for /clr:safe as
| well as the other intrinsic types you mentioned.
|

Very true, but it's usage is somewhat limitted.

wchar_t wch = 'A'; // is OK
but...
wchar_t* wsp = L"Test";
wchar_t wch[] = L"123";
are not..


Willy.
 
C

Carl Daniel [VC++ MVP]

Willy said:
"Carl Daniel [VC++ MVP]"
wchar_t maps to System::Char in managed C++, so it's fine for
/clr:safe as well as the other intrinsic types you mentioned.

Very true, but it's usage is somewhat limitted.

wchar_t wch = 'A'; // is OK
but...
wchar_t* wsp = L"Test";
wchar_t wch[] = L"123";
are not..

True that.

-cd
 
P

Peter Oliphant

| If I compile with /clr:safe, which is exactly meant by saying I can't
| use "Native Types" in my code? Is a native type something such as
| float, short, or int?
No, native types are types like pointers (int* blabla) user defined native
types (class, struct...) C++ intrinsic types like wchar_t etc..

If I read this literally it sounds like one can't do any custom object
oriented programming in /clr:safe mode. After all, if a user-defined class
is a native type, and native types aren't allowed in /clr:safe mode, I can
conclude I can't define my own classes in /clr:safe mode (based on the two
statements above, the bottom one being a response for the top one).

Or are you making a distinction here between 'class' and 'ref class'?

[==P==]
 
W

Willy Denoyette [MVP]

|> | If I compile with /clr:safe, which is exactly meant by saying I can't
| > | use "Native Types" in my code? Is a native type something such as
| > | float, short, or int?
|
| > No, native types are types like pointers (int* blabla) user defined
native
| > types (class, struct...) C++ intrinsic types like wchar_t etc..
|
| If I read this literally it sounds like one can't do any custom object
| oriented programming in /clr:safe mode. After all, if a user-defined class
| is a native type, and native types aren't allowed in /clr:safe mode, I can
| conclude I can't define my own classes in /clr:safe mode (based on the two
| statements above, the bottom one being a response for the top one).
|
| Or are you making a distinction here between 'class' and 'ref class'?
|

Yep, this only applies to C++ class and struct, that's what I meant with ...
user defined native types ..
Sorry for the confusion.

Willy.
 
P

Peter Oliphant

Willy,

No apology needed, I learned something new! I should be thanking you... : )

[and that rhymed...lol]

[==P==]
 

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