Non-D linkage with out and inout parameters.

Jeremie Pelletier jeremiep at gmail.com
Sun Mar 8 12:06:13 PDT 2009


I would like to propose a change in the behavior of out and inout parameters on functions declared without the D linkage type so they behave just like they would in their native language, and the keywords are kept as compiler hints rather than automatically handling the pointer. So for example, it wouldn't be necessary for the compiler to initialize the value to a out parameter but yet allow explicit dereference in the call.

Here's an example to illustrate the syntax:
---
extern(Windows) void GetLocalTime(out LPSYSTEMTIME lpSystemTime);

unittest {
    /// D linkage, normal out behavior
    void MyGetLocalTime(out SYSTEMTIME st) {
       /// stdcall linkage, native out behavior
       GetLocalTime(&st);
    }

    SYSTEMTIME st; /// Should not get initialized here
    MyGetLocalTime(st);
}
---

The main rationale behind it is to keep native behavior to functions we've already been using for years while not having to modify the parameters declaration for D functions. So it wouldn't break existing code to add out and inout to imported functions, it would just allow for better optimizations and documentations.




More information about the Digitalmars-d mailing list