Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7795541
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T23:05:59+00:00 2026-06-01T23:05:59+00:00

int __cdecl ccall(int i) { wprintf(Lccall(%d), i); return 0; } int __stdcall stdcall(int i)

  • 0
int __cdecl ccall(int i)
{
    wprintf(L"ccall(%d)", i);
    return 0;
}

int __stdcall stdcall(int i)
{
    wprintf(L"stdcall(%d)", i);
    return 0;
}

int __cdecl wmain(int argc, wchar_t **argv)
{
    std::function<int(int)> fnc = ccall;
    std::function<int(int)> fnstd = stdcall;

    fnc(10); // printed well
    fnstd(100); // printed well
    return 0;
}

I was concerned how do I assign a __stdcall function to std::function object.
But without any specifying calling convention, it looks like working fine. How can std::function know what calling convention is?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T23:06:00+00:00Added an answer on June 1, 2026 at 11:06 pm

    std::function is able to store function pointers that use any calling convention.

    § 20.8.11.2:

    The function class template provides polymorphic wrappers that generalize the notion of a function pointer. Wrappers can store, copy, and call arbitrary callable objects (20.8.1), given a call signature (20.8.1), allowing functions to be first-class objects.

    As John Calsbeek added: There is nothing in particular in the standard concerning the calling conventions, but the compilers are doing their job and function pointers contain the information about the convention.

    With function pointers you would need to specify the unusual calling convention:

    typedef int(* c_ptr_t)(int);
    typedef int(__stdcall * std_ptr_t)(int);
    
    c_ptr_t c_ptr = ccall;
    std_ptr_t std_ptr = stdcall;
    
    // But std::function doesn't mind:
    std::function<int(int)> fnc = c_ptr;
    std::function<int(int)> fnstd = std_ptr;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Could someone help explain this code to me? .text:00401270 ; int __cdecl main(int argc,const
I am inside a function with some arguments. Let's say: __cdecl function(int a,int b,long
Compiling this simple function with MSVC2008, in Debug mode: int __cdecl sum(int a, int
int somefunction(bool a) { try { if(a) throw Error(msg); return 2; } catch (Error
int main(void) { std::string foo(foo); } My understanding is that the above code uses
I use the following types to create a new function at runtime: typedef int
It is a simple sample. CodeDLL.cpp File: extern C { __declspec(dllexport) int __cdecl SimulateGameDLL
in c++ I have such function extern C _declspec(dllexport) uint8* bufferOperations(uint8* incoming, int size)
Here's a simple example: #include <stdlib.h> int main(void) { _set_error_mode(_OUT_TO_STDERR); return EXIT_SUCCESS; } When
I have the following native function interface in C++: int func1(void* param, int sizeOfParam).

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.