64bit Machine C implicit-function-declaration function returns pointer address value truncation problem

Source: Internet
Author: User
Tags truncated

Yesterday encountered a problem, 32bit machine normal, but 64bit machine crash, the problem simplified the next func_a.h declared MyStruct * func_a (); FUNC_A.C defines the

MyStruct * FUNC_A ()

{//mystruct * inner for Memory request and assignment//print%p, inner-----Address1 0x7ff87804b4a8return inner;} FUNC_B.C called the Func_a function (But there is no statement containing func_a.) mystruct * pt_mst = func_a ();//print Pt_mst, find address value is not address1,0xffffffff7804b4a8, address value is truncated It is normal to try to return from the function parameter using a level two pointer. Find the same problem on StackOverflow Http://stackoverflow.com/questions/23144151/64-bit-function-returns-32-bit-pointer

by default all return values is int. So if a prototype are missing for function then compiler treats the return value as 32-bit and

Generates code for 32-bit return value. thats when your upper 4 bytes gets truncated.

The implicit-function-declaration warning of the FUNC_A function was seen in the compiled log, which is common, but because Func_a's usage (return pointer) and 64bit machine triggered the mine. Good programming habits, Laosheng re-talk, warning and compile error also need to deal with, eliminate warnning is good habit ...

64bit Machine C implicit-function-declaration function returns pointer address value truncation problem

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.