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
1
vote
0 answers

Call MASM function in StdCall convention

I write a program in C, in visual studio 2015, and I have a masm module in it. I want to define some of the functions to be called as stdcall instead of the default cdecl. is there a way do that? My goal is to skip the stack cleanup in the caller…
macro_controller
  • 1,469
  • 1
  • 14
  • 32
1
vote
0 answers

Procedure not returning to C correctly in asm?

I have a simple findAverage procedure written in assembly language that I am trying to call from a C main program. I had it working for a while, but all of a sudden it gives me this error when the procedure hits ret: Unhandled exception at…
Dane Lowrey
  • 170
  • 1
  • 10
1
vote
1 answer

Mix cdecl and stdcall calling conventions

I have an already built static library on Windows VS2012 (.lib), compiled with the stdcall convention. When I say "already built", I mean unfortunatedly I cannot rebuild it with the calling convention of my choice. Is it possible to call a function…
GaTTaCa
  • 459
  • 6
  • 18
1
vote
1 answer

How to preserve the state of the registers when creating a cdecl function?

I am writing a function that uses the cdecl calling convention, and so I need to make sure that the state of the registers is preserved as they were before calling the function. My question is how this is usually performed. Is it just a matter of…
user4420637
1
vote
0 answers

Where is cdecl documented?

I'm writing a simple C compiler for x86 on Linux, and I'd like to use the cdecl calling convention (gcc uses it, and it seems to be pretty common). However, I can't find any official or definitive documentation. Wikipedia has a description and an…
Wilfred Hughes
  • 29,846
  • 15
  • 139
  • 192
1
vote
1 answer

Incrementing %esp and CDECL

I've been reading up on the x86 stack and the CDECL convention and read something that confused me. Among the caller's responsibilities listed were popping the parameters, using them or simply incrementing %esp to remove them. How does that last…
user8814
  • 94
  • 6
1
vote
1 answer

Doesn't printf use __cdecl in VS2013

There is a such question in my interview ,today. #include int main(void) { char *s="123456790"; printf("%c,%c",*(char *)((int *)s+++1),*s); return 0; } my answer is 5,1, but the Interviewer said it's 5,2! Of course, I knew…
sol H
  • 13
  • 2
1
vote
1 answer

In cdecl, is the callee required to preserve the arguments passed to it?

Say I have void f(int a, int b, int c) { g(a, b, c); h(a, b, c); } in x86 assembly like this: section .text f: pop dword [res_1] call g ; g(a, b, c) call h ; h(a, b, c) push dword [res_1] ret section…
jcai
  • 3,448
  • 3
  • 21
  • 36
1
vote
3 answers

Why is there no companion instruction to leave?

Why is there no companion instruction to leave on the x86? That way, pushl %ebp movl %esp,%ebp pushl $3 popl %eax leave ret could become: enter #or something pushl $3 popl %eax leave ret Isn't that just faster in general?
Keeley Hoek
  • 543
  • 4
  • 18
1
vote
0 answers

How to write a managed C# dll that follows cdecl specification

I need to write a DLL, that follows the cdecl specification, so that it can be called from an existing application which allows embedding of dlls. Can I write a dll using C# and the dotnet Framework, that follows the cdecl specification? How can…
rhuebscher
  • 11
  • 2
1
vote
1 answer

How to change procedure name in DLL

When I compile DLL in C++ Builder with my procedure extern "C" __declspec(dllexport) __cdecl void show_m(void) { MessageBox(NULL, "MSG", "COTI DLL", MB_OK |MB_ICONINFORMATION); } I can see in depends.exe that name of my procedure is _show_m. How…
Jacek
  • 59
  • 3
1
vote
2 answers

Dumpbin shows strange method name (generating exporting function in MS Visual C++)

I have created new Win32 project in my VS and have selected Dynamic Library ( *.dll ) for this aim. I have defined some exporting function in the main file: __declspec(dllexport) int TestCall(void) { int value = 4 / 2; std::cout <<…
Secret
  • 2,627
  • 7
  • 32
  • 46
1
vote
0 answers

_beginthread implementation in Windows Forms Application

I've tried to create thread with simple _beginthread function in Windows Forms Application (I did it successfully with making console application. private: System::Void __cdecl counter() { do { Sleep(1); …
Staly
  • 85
  • 7
1
vote
2 answers

g++ cdecl calling convention with Steinberg VST SDK

As far as I have researched, I see that GNU C by default uses cdecl for function calls. The VST SDK explicitly defines the calls as cdecl when compiling with GNU C, and it spits out the following error: again.cpp:27:15: warning: multi-character…
Loke
  • 249
  • 1
  • 6
  • 14
0
votes
2 answers

Sending big amount of bytes from Swift to Python with types and @_cdecl

I have two simple functions, one pass to another array of UInts. When I pass small array of 20 UInts function works, but when I pass 21576 Uints function returns small amount of bites, why is it happened? I checked UnsafeMutablePointer inside…