Error: Cast from 'Char * 'to 'int' loses precision

Source: Internet
Author: User

An error occurs during compilation:

Error: cast from 'Char * 'to 'int' loses precision

Cause: the program exists.

Char * addrCom; addrCom =... // assign the value if (-1 = (int) addrCom) // causes a compilation error {......}

The above is implicit conversion. Change it to Standard C ++ display type conversion: static_cast <int> or this is reinterpret_cast <int>

Still:

Error: cast from 'Char * 'to 'int' loses precision

Finally google a bit, found the answer: http://stackoverflow.com/questions/1640423/error-cast-from-void-to-int-loses-precision

ShouldChange (int) addrCom to (long) addrComYou can.

Explanation:

Because the compiled system is linux64-bit, the pointer type is equal to the long type (8B) and the int type 4B, the loses precision will appear.

Therefore, first convert char * --> long, and then convert it from long to int automatically and implicitly.

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.