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?

3
  • can you show the c code you are compiling ?
    – tristan
    Aug 29, 2014 at 8:01
  • I don't know whether that's the only problem, but yes, the function pointer will need to be declared as stdcall. Aug 29, 2014 at 11:44
  • Yup, that fixed it, thanks Harry Used this: stackoverflow.com/questions/5298394/…
    – ethrzael
    Aug 29, 2014 at 12:18

1 Answer 1

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); 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.