Non-D linkage with out and inout parameters.

Robert Fraser fraserofthenight at gmail.com
Sun Mar 8 18:28:48 PDT 2009


Jeremie Pelletier wrote:
> 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.
> 

I agree with the proposal, but for the optimization use case, use:
SYSTEMTIME st = void;
This won't initialize st to zero.



More information about the Digitalmars-d mailing list