top | item 40083759

(no title)

vrotaru | 1 year 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.

discuss

order

magicalhippo|1 year ago

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...

pjmlp|1 year ago

Since the Turbo Pascal days actually.

JonChesterfield|1 year ago

C for example does this, albeit in compiler extensions, and with a longer tag than #.

IshKebab|1 year ago

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

dgellow|1 year ago

Is it similar to Zig’s callconv keyword?

vrotaru|1 year ago

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.