Let's take a preliminary look at the differences in compilers-general Linux technology-Linux programming and kernel information. The following is a detailed description. By Jackie
I have been writing a program for a long time, but I haven't discussed it in depth. Many things are stuck in the stage of ignorance. It is estimated that they will be laughed at by their peers. I have always heard that the machine commands compiled by different compilers are different. Unfortunately, I did not know it. I found some differences when I tested the string length with strlen today, so keep a record and use it as a memory for your own learning.
Result:
WINXP + VC6.0 compilation and running result 68 (a bit dizzy, I applied for a heap but 64 said ).
LINUX (debian4.0) + g ++ compilation and running result 0.
Debugging:
After applying for VC6.0 and pStr to the heap space, the content is: "Tunnel, tunnel, and tunnel ", there are four ''after 32" swallowed ", and the result of strlen is 68.
G ++, The pStr content is empty, there is no content in the heap space, and the result of strlen is 0.
Conclusion:
After applying for heap space, the VC6.0 compiler does not initialize the heap space. Therefore, the heap space has content. As to why there are four ''later, further research is required;
After applying for heap space, the g ++ compiler initializes the heap space to 0, so the running result is 0.
Correction:
Place the initialization statement after the memory application. Then, execute the statement again and the result is 0.
Memset (pstr, NULL, 64 );
Supplement:
If the test runs sizeof (pStr), the result is 4.
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