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