且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

64位GCC混合32位和64位指针

更新时间:2022-05-17 02:08:38

将其添加为答案,因为它包含原始问题的部分难题":

Adding this as an answer, as it contains "part of the puzzle" for the original question:

只要编译器可以[通过例如指定满足此要求的内存模型]确定.LC4在前4GB之内,它就可以执行此操作. %edx将被加载LC4地址的32位,并且高位被设置为零,因此,当edc_function()被调用时,它可以使用%rdx的完整64位,并且只要地址在该范围之内即可.较低的4GB,它将正常工作.

As long as the compiler can determine [by for example specifying a memorymodel that satisfies this] that .LC4 is within the first 4GB, it can do this. %edx will be loaded with 32 bits of the address of LC4, and upper bits set to zero, so when the edc_function() is called, it can use the full 64-bits of %rdx, and as long as the address is within the lower 4GB, it will work out fine.