How to Write C ++ code

Source: Internet
Author: User

Many people have a headache when talking about C ++ code. They often feel that editing long and messy code is not starting, well, after reading this article, you will no longer be troubled by complicated code problems. I hope you can get help.

The code for the C ++ program is as follows:

 
 
  1. # Include
  2. # Include
  3. Using std: cout;
  4. Using std: endl;
  5.  
  6. Struct prediction_registration
  7. {
  8. Prediction_registration * prev;
  9. DWORD handler;
  10. };
  11.  
  12. Prediction_disposition myHandler (
  13. _ EXCEPTION_RECORD * ExcRecord,
  14. Void * EstablisherFrame,
  15. _ CONTEXT * ContextRecord,
  16. Void * DispatcherContext)
  17. {
  18. Cout<<"In the exception handler"<< Endl;
  19. Cout<<"Just a demo. exiting ..."<< Endl;
  20. Exit (0 );
  21. Return ExceptionContinueExecution; // It will not run to this
  22. }
  23.  
  24. IntG_div=0;
  25.  
  26. Void bar ()
  27. {
  28. // Initialize a prediction_registration Structure
  29. Prediction_registration reg ,*Preg=®
  30. Reg. handler= (DWORD) myHandler;
  31.  
  32. // Obtain the "Header" of the current Exception Handling Link"
  33. DWORD prev;
  34. _ Asm
  35. {
  36. Mov EAX, FS: [0]
  37. Mov prev, EAX
  38. }
  39. Reg. prev= (Prediction_registration *) prev;
  40.  
  41. // Register!
  42. _ Asm
  43. {
  44. Mov EAX, preg
  45. Mov FS: [0], EAX
  46. }
  47.  
  48. // Generate an exception
  49. IntJ=10/G_div; // exception, Division by zero Overflow
  50. }
  51.  
  52. Int main ()
  53. {
  54. Bar ();
  55. Return 0;
  56. }

The above is my summary of the C ++ program code. I will continue to update the code, so stay tuned!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.