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>


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

Finally google a bit, found the answer:

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


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: 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.