Importance of global variable Initialization

Source: Internet
Author: User

During this period, we have been maintaining the "Total Station Distance Accuracy Test" software compiled by VB6. Because two baselines are added to the new requirements, and the prism spacing of each baseline is not the same, therefore, I used a Boolean global variable and designed to assign a value to the global variable in the event of clicking a button. Here I did not consider the issue of global variable initialization, of course, the initialization of this variable has no effect on the program itself.

However, I did not have the sensitivity to global variable initialization, which led to problems later. The reason is that I hope the software can do better, this prevents data errors once the baseline is blocked. Therefore, I add a global variable to store the value of each ranging task, I compared the ranging value with the global variable (the last ranging to) and analyzed the gap between the two values to determine whether the data is valid automatically. After the software is modified, after testing, it solved the problem of data errors caused by blocking. However, when I repeatedly used the software, the data could not be displayed, the program has been stuck, and I don't know why. I have reproduced the problem several times and suddenly realized the problem of global variables. Before using global variables, initialize it, compile and run it, and solve the problem. This reminds me of the previous R & D department meeting. The boss said that in the future, the coding rules of our software must follow a "global variables must be initialized before use !"

Here, I will summarize again -- the global variables must be initialized before use!

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.