The running results of the same program in Windows and Linux are different.

Source: Internet
Author: User
The running result of the same program in Windows is different from that in Linux-Linux general technology-Linux programming and kernel information. The following is a detailed description. Recently, I wrote a small program for numerical computation in C language. In order to speed up debugging, in addition to running on Linux, I also run on some other Windows platforms. In Linux, the compiler uses g ++ and in Windows, the compiling environment is Visual Stdio2005. After debugging on Windows, the source code is directly copied from Windows to the Linux platform for running. However, the running results in Linux are completely different. I had to continue debugging in Linux and use GDB for single-step tracking. I still did not find the problem. After a whole day of hard work, we had to open the Visual Stdio2005 debugging window in Windows and GDB in Linux for single-step tracking at the same time. Only then can we find that the two compiling environments have different return values for the absolute value function abs. In Visual Stdio2005, the overload function fabs () is automatically called according to the parameter type, while in g ++? Orange emperor? Bs (), the absolute value of the floating point type is directly converted into an integer, which leads to a large difference in the result.
Related Article

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.