[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: C++ aliases in <netdb.h>
From: |
Gisle Vanem |
Subject: |
Re: C++ aliases in <netdb.h> |
Date: |
Sat, 17 Dec 2016 10:32:57 +0100 |
User-agent: |
Mozilla/5.0 (Windows NT 10.0; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.5.0 |
Pedro Alves wrote:
> Can't see how that can run fine? The compiler will set up the call
> assuming cdecl convention, while the called function has stdcall
> convention.
I would expect the 'reinterpret_cast<type>(::getaddrinfo)' to fix that.
With this little example:
#include <config.h>
#include <netdb.h>
int main (void)
{
struct addrinfo *res;
gnulib_::getaddrinfo ("www.google.com", "http", NULL, &res);
return (0);
}
A dis-assembly shows:
.rdata, "dr2"
address@hidden@@address@hidden@B: 00 00 00 00
$SG37638: "http"
$SG37639: "www.google.com"
.text, "crx4"
_main:
push ebp
mov ebp,esp
push ecx
lea eax,-0x4[ebp]
push eax
push 0x00000000
push $SG37638
push $SG37639
mov ecx,address@hidden@@address@hidden@B
call address@hidden@@QBEP6AHPBD0PBUaddrinfo@@PAPAU2@@ZXZ
call eax
add esp,0x00000010
xor eax,eax
mov esp,ebp
pop ebp
ret
address@hidden@@QBEP6AHPBD0PBUaddrinfo@@PAPAU2@@ZXZ:
push ebp
mov ebp,esp
push ecx
mov dword ptr -0x4[ebp],ecx
mov eax,dword ptr address@hidden
mov esp,ebp
pop ebp
ret
Running the program shows that 'address@hidden' gets the arguments
in the right order. So '__stdcall' must be in effect.
> Are all MSVC C run time functions __stdcall, or just a few?
> It's been a long while since I used MSVC.
getaddrinfo() etc. is not a 'run time function' but a SDK functions.
Almost all functions in the Windows SDK are __stdcall. The runtime
functions are __cdecl.
--
--gv