Snprintf/_ snprintf function differences between different platforms

Source: Internet
Author: User

The original article focuses on msdn documentation. It is also the previous version. I wonder if the new version has changed. After installing vs2013 Express, try again.
The main problem with this function is that it is not defined in the C standard and provided by various manufacturers themselves. GCC provides snprintf, and Ms provides a version with a prefix underscore. Therefore, there is no standard definition of function behavior, and there is a difference in implementation. It is mainly manifested in the returned value and the behavior of the output buffer.
The GCC version automatically adds "\ 0" to the end of the target string when the source string length is greater than or equal to size. The returned value is the source String Length;
If the source string length is greater than or equal to size, "\ 0" is not automatically added to the end of the target string. If the returned value exceeds the size, a negative value is returned;
In contrast, the GCC version is safer.
It seems that there are few things without a standard definition to be used, so it may be difficult to get stuck if you don't know. Maybe the c Standard Committee will include snprintf into the standard one day, so the implementation of one of them will definitely have to be changed.

Snprintf/_ snprintf function differences between different platforms

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.