-2
//cdecl function pointer 
int(__cdecl* pfn)(int, int, int, int, int, int, int, int);

//stdcall function 
int  __stdcall HHH(int i, int i1, int i2, int i3, int i4, int i5, int i6, int i7)
{
    cout << "HHH" << (i + i1 + i2 + i3 + i4 + i5 + i6 + i7) << endl;
    return 1;
}

int main()
{
    pfn = HHH;
    cout << pfn(1, 2, 3, 4, 5, 6, 7, 8) << endl;
}

I think a stdcall function can't assign to cdecl function pointer,but in vc++2022,this worked every well. I don't know why? Thank you!

πάντα ῥεῖ
  • 1
  • 13
  • 116
  • 190
  • What exactly did you expect? Any error messages or warnings you experienced with earlier msvc versions? – πάντα ῥεῖ Jan 30 '22 at 03:10
  • After adding the missing `#include`'s and `std::` (you really should have done this yourself), using Visual Studio 2019, version 16.11.9, the error is: `error C2440: '=': cannot convert from 'int (__stdcall *)(int,int,int,int,int,int,int,int)' to 'int (__cdecl *)(int,int,int,int,int,int,int,int)'` – PaulMcKenzie Jan 30 '22 at 03:13
  • 3
    Are you building a 64-bit executable, by any chance? As I understand, x64 only has one calling convention; `__cdecl` and `__stdcall` are no-ops there. – Igor Tandetnik Jan 30 '22 at 03:31
  • @Igor Tandetnik is right。i am building a 64-bit version。i have test , if build a 32-bit version it tells me a error c2440 as PaulMcKenzie post – largesky Jan 30 '22 at 05:04

1 Answers1

0

Igor Tandetnik is right。i am building a 64-bit version。I have tested , if build a 32-bit version it tells me a error c2440 as PaulMcKenzie posted

  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jan 30 '22 at 08:20