← Back to context

Comment by vrotaru

2 years ago

There was an interesting aproach to this, in an experimental language some time ago

   fn f1 (x, y) #-> // Use C calling conventions

   fn f2 (x, y) -> // use fast calling conventions

The first one was mostly for interacting with C code, and the compiler knew how to call each function.

Delphi, and I'm sure others, have had[1] this for ages:

When you declare a procedure or function, you can specify a calling convention using one of the directives register, pascal, cdecl, stdcall, safecall, and winapi.

As in your example, cdecl is for calling C code, while stdcall/winapi on Windows for calling Windows APIs.

[1]: https://docwiki.embarcadero.com/RADStudio/Sydney/en/Procedur...

Terrible taste. Why would you hide such an infrequently used feature behind a single character? In this case you should absolutely use a keyword.

Is it similar to Zig’s callconv keyword?

  • Guess so. Unfamiliar with Zig. The point is that not a "all or nothing" strategy for a compilation unit.

    Debugger writers may not be happy, but maybe lldb supports all conventions supported by llvm.

    • Debugger writers have dealt with different calling conventions for decades. The notion predates C even. They can handle it just fine.