Out parameters and initialization
Ivan Senji
ivan.senji_REMOVE_ at _THIS__gmail.com
Sun Feb 26 16:21:27 PST 2006
Unknown W. Brackets wrote:
> Yes, but this is a topic about a bug. We are no longer really talking
> about the bug.
Do we agree then that the bug is that
void f(out int x = 5) isn't an error?
>
> If you used your workaround, you would have:
>
> 1. Extra global variables somewhere in memory, which may not be desirable.
But as Regan said, possibly only one for each type.
>
> 2. Uninitialized variables, from what I can tell (out parameters are
> normally initialized to their default state at the beginning of the
> function.) This may cause unexpected/hard-to-reproduce bugs.
Same happens here.
void f(out int x = globalX) -> globalX is initialized to int.init.
No bugs here.
>
> 3. Requirements to use synchronized blocks around accesses to the
> variables, which would normally not be necessary with typical out
> parameters. This would be needed because the function may depend on the
> global variables not changing mid-function, but the function might get
> called numerous times concurrently in multiple threads.
I agree this is a problem in multithreaded enviroment.
>
> It's true that programming involves the above all the time, but they can
> all be avoided in this case by not using your described method. As
> such, I consider them flaws in the proposed method.
But there isn't any other way to solve what you wanted? Or is there?
I mean wanting not allways to pass out arguments to a function.
Atleast not other way without changing the language so that out default
params are made strange and inconsistent.
But I agree this discussion sholud probably end soon :)
More information about the Digitalmars-d-bugs
mailing list