Archive for the ‘The Basics’ Category

x86 calling conventions

Wednesday, January 16th, 2008

This is the first article of a (I hope) long series of articles about ‘The Basics: What everyone should know about’ :)

The calling convention defines the way a function or a piece of code should arrange data before calling a function, and what to do after. It responds to questions like “In which order should I pass the arguments ?”, “Should I clean something ?”, “Where is the result ?”, …

There is a lot of different calling conventions. Here are the 3 I see the most of the time:

  • cdecl
  • stdcall
  • fastcall

cdecl convention

The cdecl convention is the default one used when working with a C compiler like GCC or MSVC. To use the cdecl scheme for a function, you can use this syntax (GCC): (more…)