0

So I have a function called sockio() that takes a function pointer for either the send() or recv() functions in Winsock 1.1 but I get an error when I try to pass either as an argument of my function pointer type iofunc, defined below.

I can't seem to make them match up so that it'll let me pass in send() or recv(), why is this?

// my function pointer typedef
typedef int (*iofunc)(SOCKET, const char*, size_t, int); 

// sockio function prototype
static int sockio(int socket, sockio_buf* buf, iofunc io); 

Heres the error it gives me when I try to compile in Visual C++ 2010:

1>c:\...\sockio.c(24): error C2440: 'function':
  cannot convert from 'int (__stdcall *)(SOCKET,const char *,int,int)' to 'iofunc'
1>c:\...\sockio.c(24):
  warning C4024: 'sockio': different types for formal and actual parameter 3

All the parameters look the same to me. Is it anything to do with the (__stdcall *) bit?

ethrzael
  • 3
  • 3

1 Answers1

0

Your typedef is missing a calling convention, so C's default calling convention (usually __cdecl) is used instead. send() and recv() use the __stdcall calling convention:

typedef int (__stdcall *iofunc)(SOCKET, const char*, size_t, int); 
Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770