| Thread overview | |||||
|---|---|---|---|---|---|
|
March 08, 2009 Non-D linkage with out and inout parameters. | ||||
|---|---|---|---|---|
| ||||
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.
| ||||
March 09, 2009 Re: Non-D linkage with out and inout parameters. | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Jeremie Pelletier | 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.
| |||
March 09, 2009 Re: Non-D linkage with out and inout parameters. | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Robert Fraser | Robert Fraser Wrote:
> I agree with the proposal, but for the optimization use case, use:
> SYSTEMTIME st = void;
> This won't initialize st to zero.
This is what I currently do but I would assume it's better suited for variables used in the current scope instead of passed as an out parameter to the next statement. So it would end up being just like doing "uint i = 0;", it works, but doing "uint i;" does the same.
| |||
Copyright © 1999-2021 by the D Language Foundation
Permalink
Reply