Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the actual function of the C# project setting "Allow unsafe code"

I was wondering if the C# project setting "Allow unsafe code" applies only to unsafe C# code in the project itself, or is it necessary to set this option when linking in a native C++ DLL? What about linking in a managed DLL that itself links to a native DLL? What does this option really do, under the hood?

like image 495
Brian Stewart Avatar asked Oct 24 '08 14:10

Brian Stewart


People also ask

What is actual argument in C?

The arguments that are passed in a function call are called actual arguments. These arguments are defined in the calling function. These are the variables or expressions referenced in the parameter list of a subprogram call.

What is function type in C?

There are two types of functions in C programming: Library Functions: are the functions which are declared in the C header files such as scanf(), printf(), gets(), puts(), ceil(), floor() etc. User-defined functions: are the functions which are created by the C programmer, so that he/she can use it many times.

What is actual and formal argument in C?

The variables declared in the function prototype or definition are known as Formal arguments and the values that are passed to the called function from the main function are known as Actual arguments. The actual arguments and formal arguments must match in number, type, and order.


3 Answers

It has to do with the "unsafe" keyword in C#. "unsafe" turns off all the checks that would normally happen and allow you to directly access the memory. it doesn't refer to calling native C++ DLL's or interfaces.

like image 155
Nick Berardi Avatar answered Oct 20 '22 17:10

Nick Berardi


It allows you to use the "unsafe" block.

unsafe(...)
{
}
like image 24
Maxime Rouiller Avatar answered Oct 20 '22 18:10

Maxime Rouiller


This just relates to the use of unsafe blocks (where pointers can be used). It does not govern P/Invoke.

like image 29
Jeff Yates Avatar answered Oct 20 '22 17:10

Jeff Yates