Usage and attention of uses_conversion

Source: Internet
Author: User

 

Uses_conversion is used to convert the type. For example, we have the following common problems:

During socket programming, the cstring type is generally used for entering IP addresses from the interface. However, inet_addr in sockaddr_in is a const char * and we cannot use cstring directly. We can use the T2A () Macro.

Sockaddr_in localaddr;

Cstring m_ip = l "192.168.1.2 ";

Uses_conversion;
Localaddr. sin_family = af_inet;
Localaddr. sin_addr.s_un.s_addr = inet_addr (T2A (m_ip ));

 

Of course, the use of uses_conversion is also a very important issue.

Uses_conversion: it allocates space on the stack, which means that you will not be released before the function ends. Do not use a while loop in a function to execute it, otherwise the stack space will be allocated immediately (the stack space is generally only 2 m, very small ).

 

Usage and attention of uses_conversion

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.