1

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 example. Raymond Chen has a short summary. I didn't spot anything relevant in the C11 specification either.

Is there canonical documentation for cdecl?

Wilfred Hughes
  • 29,846
  • 15
  • 139
  • 192
  • 1
    It is entirely up to you to define it, as long as you can support a variable number of arguments. In other words, you need to make printf() work. Otherwise easy to reverse engineer when you look at the code generated by another compiler that works on the same platform. The platform is never a minor detail you should ever leave out of a question like this btw. – Hans Passant Sep 20 '14 at 12:49
  • 1
    Look at the docs of the system-compiler you want to be compatible with? – Deduplicator Sep 20 '14 at 13:05
  • 4
    You don't want `cdecl`, but you need to understand what is an [ABI](http://en.wikipedia.org/wiki/Application_binary_interface). See e.g. [Linux AMD64 ABI](http://www.x86-64.org/documentation_folder/abi-0.99.pdf). ABI specifications are implementation specific so are not part of the C11 (or C99) standards. – Basile Starynkevitch Sep 20 '14 at 13:06
  • I've updated the question to say which architecture and operating system. – Wilfred Hughes Sep 20 '14 at 13:41
  • 1
    @BasileStarynkevitch: I think that comment is an answer, although it might be good to include a link to https://refspecs.linuxbase.org/ which also points to the i386 ABI. – rici Sep 20 '14 at 14:59

0 Answers0