Questions tagged [cdecl]

Anything related to the `cdecl` calling convention, i.e. one of the common subroutine calling conventions used on systems with x86 architecture.

Anything related to the cdecl calling convention, i.e. one of the common subroutine calling conventions used on systems with x86 architecture.

See Wikipedia on:

101 questions
102
votes
9 answers

stdcall and cdecl

There are (among others) two types of calling conventions - stdcall and cdecl. I have few questions on them: When a cdecl function is called, how does a caller know if it should free up the stack ? At the call site, does the caller know if the…
Rakesh Agarwal
  • 3,009
  • 9
  • 33
  • 40
70
votes
2 answers

Why are Cdecl calls often mismatched in the "standard" P/Invoke Convention?

I am working on a rather large codebase in which C++ functionality is P/Invoked from C#. There are many calls in our codebase such as... C++: extern "C" int __stdcall InvokedFunction(int); With a corresponding C#: [DllImport("CPlusPlus.dll",…
Kadaj Nakamura
  • 923
  • 1
  • 10
  • 24
48
votes
10 answers

How do you read C declarations?

I have heard of some methods, but none of them have stuck. Personally I try to avoid complex types in C and try to break them into component typedef. I'm now faced with maintaining some legacy code from a so called 'three star programmer', and I'm…
1729
  • 4,961
  • 2
  • 28
  • 17
41
votes
8 answers

What does "cdecl" stand for?

Yes, I know that "cdecl" is the name of a prominent calling convention, so please don't explain calling conventions to me. What I'm asking is what the abbreviation (?) "cdecl" actually stands for. I think it's a poor naming choice, because at first…
fredoverflow
  • 256,549
  • 94
  • 388
  • 662
13
votes
2 answers

Why should I not use __fastcall instead the standard __cdecl?

I'd listening some people saying __fastcall is faster than __cdecl and __stdcall cause it puts two parameters in register, instead of the one of other calls; but, in other hand, this is not the standard used in C. I would like to know what makes…
lucastamoios
  • 562
  • 1
  • 8
  • 22
11
votes
11 answers

Is there a way to call member function without .* or ->* operator

Below method of calling D::foo function via pointer-to-member function will generate error: must use .* or ->* to call pointer-to-member function in 'f (...)' .. of course that is not how we call pointer-to-member functions. The correct way of…
Vishnu Kanwar
  • 761
  • 5
  • 22
10
votes
4 answers

Changing Calling Convention

I have a 3rd party C API that expects a __stdcall callback function. My code has an externally-provided __cdecl callback function. I cannot pass my function pointer to the C-API as they are considered different types. Bypassing the type system and…
Adi Shavit
  • 16,743
  • 5
  • 67
  • 137
8
votes
1 answer

C# get the list of unmanaged C dll exports

I have a C dll with exported functions I can use the command-line tool dumpbin.exe /EXPORTS to extract the list of exported functions, and then use them in my C# code to (successfully) call these functions. Is there a way to get this…
ZivF
  • 125
  • 1
  • 8
7
votes
2 answers

C calling convention: who cleans the stack in variadic functions vs normal functions?

There are some calling conventions (e.g pascal, stdcall) but as far as I am concerned, C does use cdecl (C-declared). Each of these conventions are slightly different in the way the caller loads the parameters onto the stack, respectively which…
Cătălina Sîrbu
  • 1,253
  • 9
  • 30
7
votes
1 answer

AccessViolationException when PInvoking C++ DLL (cdecl calling convention problem?)

I've spent all day researching this, and I'm none the wiser: I have a C# DLL which PInvokes a method in a C++ DLL. I have had no problems doing this when compiling in Debug mode, but when compiling in Release mode I get an AccessViolationException.…
PNielsen
  • 123
  • 5
7
votes
3 answers

how are structs passed as parameters in assembly

How are structs passed as parameters in assembly? Since structs have sizes large than normal are the individual fields passed sequentially? If so are they in reverse order like normal parameters? Are their any differences between cdecl and stdcall?
7
votes
5 answers

In C++, do variadic functions (those with ... at the end of the parameter list) necessarily follow the __cdecl calling convention?

I know that __stdcall functions can't have ellipses, but I want to be sure there are no platforms that support the stdarg.h functions for calling conventions other than __cdecl or __stdcall.
Ben
  • 585
  • 1
  • 4
  • 19
7
votes
1 answer

Why does go's compiler "gc" use a different calling convention than C?

C uses the cdecl, which I've looked into and called with from assembly. It feels well enough, so why break the compatibility? Why was another convention needed?
galva
  • 1,253
  • 10
  • 17
6
votes
3 answers

__cdecl forcing prefix with underscore

My company provides a third party with a DLL which provides them with API functions they can use to connect to our application. The DLL was written in VC9, and the API functions used VC's default calling convention (__cdecl). The third party has…
Hoppy
  • 720
  • 2
  • 12
  • 24
6
votes
1 answer

In the CDECL calling convention, can I reuse the arguments I pushed onto the stack?

In the GCC cdecl calling convention, can I rely on the arguments I pushed onto the stack to be the same after the call has returned? Even when mixing ASM and C and with optimization (-O2) enabled?
basdp
  • 193
  • 11
1
2 3 4 5 6 7