Discussion on the cross-border problem of C + +

Source: Internet
Author: User

Originated from the problems I encountered two times:

For the first time, you need to add a code to the program that crashes the program, and I added an array of out-of-bounds code. Similar to

int a[3] = {0};

A[4] = 1;

On the Win32 platform, the program compiles and runs using the QT Creator development environment, and the programs are successfully hung up at runtime. Then consistent to the Linux platform, the use of g++ compiled to run, the program is running properly, completely did not hang off.

The second time, the code uses a vector, using subscript vector[i] to access a value, inadvertently causing I to 1. The same on the Linux platform, g++ compiled run, all normal, also got the correct running result. The same code hangs off on the Win32.

So it seems that the Linux platform or the g++ compiler has its own handling of subscript cross-border issues, causing the program to not hang. The Win32 platform or compiler on the platform does not process the subscript out of bounds, and the program hangs up.

Haven't verified exactly why this is causing the situation, want to see the article if you have an idea or know the reason can tell me ^ ^

Discussion on the cross-border problem of C + +

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.