I heard people say that C # has no pointer, because it is not safe. Baidu just said this:
Now, you need to operate the hardware watchdog to know that C # can also operate the pointer.
Program environment:. Net microframework
Development tools: Visual Studio 2013
Development language: C #
Communication tool: New Life CAPTCHA Tool
Program function: our development hardware may crash in special peripheral circumstances. The solution is to use the watchdog program to discover the dead and then C # reset the MCU pointer. Restart the MCU.
C # single-chip microcomputer pointer
The procedure is as follows:
Code:
Using system; using Microsoft. spot; using system. threading; namespace doiterror {// <summary> // select generate in project properties /// select allow unsafe code in generate /// Mark unsafe modifier in class to allow use Pointer /// </Summary> public class program {// <summary> to kill hardware </Summary> Public static void main () {int A = 0; while (true) {A ++; thread. sleep (1000); debug. print (. tostring (); If (A = 20) {debug. print ("---------- execute ------------"); New testclass (). todo (); Return ;}}public unsafe class testclass {public void todo () {// declare a pointer int * I; // assign a value to the pointer, point to a nonexistent memory address I = (int *) 0x00000000; // obtain the pointer var J = * I ;}}}}
The above code implementation function: Count, 20 seconds later, the microcontroller crashes, restart continues to start.
Of course, C # supports pointer operator operations, just to ensure the security of Vs, We need to enable the pointer function;
Solution
1. Set "attribute"> "generate" in the vs project and select "allow Insecure code"
2. Add the unsafe modifier to the class where the MF program uses pointers.
3. Declare a pointer int * I; assign a non-existent memory address for I = (int *) 0x00000000; Value: var J = * I;
In this way, vs supports pointer compilation.
Then the hardware is output.
Download routine: csharp .rar
It's a cool day, and it's hard to work on code during the night. Send a beautiful girl to reduce the temperature.
Welcome to join us,Share the inspirational story of programmers.Happy programmers QQ group: