Search code examples
gccc++11g++calling-conventionstdcall

GCC ignores calling convention attribute


does anyone know why this doesnt work?

void test() [[stdcall]] {
        std::cout << "Hello World" << std::endl;
}

when I try to compile with C++11 dialect it says:

"warning: 'stdcall' attribute directive ignored [-Wattributes]"

Why is that? I have a function that really needs to have the stdcall calling convention. The default calling convention in GCC is cdecl. Any suggestions?


Solution

  • The following should work:

    #include <iostream>
    [[gnu::stdcall]]
    void test()
    {
      std::cout << "Hello World" << std::endl;
    }
    

    or you can use the old syntax __attribute__((stdcall)). Compiling with g++ -std=c++11 -m32 I get no warning.