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 9290161
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T20:21:10+00:00 2026-06-18T20:21:10+00:00

The following code was compiled with VC++ 2012: void f1(void (__stdcall *)()) {} void

  • 0

The following code was compiled with VC++ 2012:

void f1(void (__stdcall *)())
{}

void f2(void (__cdecl *)())
{}

void __cdecl h1()
{}

void __stdcall h2()
{}

int main()
{
    f1(h1); // error C2664
    f2(h2); // error C2664

    f1([](){}); // OK
    f2([](){}); // OK

    auto fn = [](){};

    f1(fn); // OK
    f2(fn); // OK
}

I think the errors are normal yet the OKs are abnormal.

So, my questions are:

  1. What’s the calling convention of a C++ lambda function?

  2. How to specify the calling convention of a C++ lambda function?

  3. If the calling convention is not defined, how to correctly recycle the stack space after having called a lambda function?

  4. Does the compiler automatically generate multiple versions of a lambda function? i.e. as the following pseudo-code:

    [] __stdcall (){};

    [] __cdecl (){}; etc.

  • 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-18T20:21:11+00:00Added an answer on June 18, 2026 at 8:21 pm

    On VC++ 2012, compiler choose automatically calling conversion for stateless lambdas (that has no capture variables) when you convert "stateless lambda to function pointer".

    MSDN C++11 Features:

    Lambdas

    […] Additionally in Visual C++ in Visual Studio 2012, stateless lambdas are convertible to function pointers. […] (The Visual C++ in Visual Studio 2012 is even better than that, because we’ve made stateless lambdas convertible to function pointers that have arbitrary calling conventions. This is important when you are using APIs that expect things like __stdcall function pointers.)


    EDITED:

    NB: The calling conversion is out of C++ Standard, it depends on other specification such as platform ABI(application binary interface).

    The following answers are based on output assembly code with /FAs compiler option.
    So it’s a mere guess, and please ask Microsoft for more detail ;P

    Q1. What’s the calling convention of a C++ lambda function?

    Q3. If the calling convention is not defined, how to correctly recycle the stack space after having called a lambda function?

    First of all, C++ lambda(-expression) is NOT a function (nor function pointer), you can call operator() to lambda object like a calling normal function.
    And output assembly code says that VC++ 2012 generates lambda-body with __thiscall calling conversion.

    Q2. How to specify the calling convention of a C++ lambda function?

    AFAIK, there is no way. (It may be only __thiscall)

    Q4. Does the compiler automatically generate multiple versions of a lambda function? i.e. as the following pseudo-code: […]

    Probably No.
    The VC++ 2012 lambda-type provides only one lambda-body implementation (void operator()()), but provides multiple "user-defined conversion to function pointer" for each calling conversion (operator return function pointer with void (__fastcall*)(void), void (__stdcall*)(void), and void (__cdecl*)(void) type).

    Here is an example;

    // input source code
    auto lm = [](){ /*lambda-body*/ };
    
    // reversed C++ code from VC++2012 output assembly code
    class lambda_UNIQUE_HASH {
      void __thiscall operator()() {
        /* lambda-body */
      }
      // user-defined conversions
      typedef void (__fastcall * fp_fastcall_t)();
      typedef void (__stdcall * fp_stdcall_t)();
      typedef void (__cdecl * fp_cdecl_t)();
      operator fp_fastcall_t() { ... }
      operator fp_stdcall_t() { ... }
      operator fp_cdecl_t() { ... }
    };
    lambda_UNIQUE_HASH lm;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

when the following code is compiled it goes into an infinite loop: int main()
The following code when compiled give this error I cannot understand why this is
The following C++ code i think is correct, but produce some warnings when compiled
I have the following code: typedef void VOID; int f(void); int g(VOID); which compiles
I have the following code compiled by gcc: #include <iostream> using namespace std; class
I compiled the following code as a shared library using g++ -shared ... :
the following piece of C++ code compiled two years ago in a suse 10.1
The following code is generating warning C6284 when compiled with /analyze on MSVC 2008
I have the following line of code which when compiled with GHC it goes
Consider the following code: #include <iostream> struct test { void public_test() { [this]() {

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.