D - in/out/inout questions
- brad beveridge (15/15) Nov 30 2003 Hi there, I've just started playing with D & am wondering about the
- Russ Lewis (13/27) Nov 30 2003 Although I see your point, I think that the current implementation makes...
Hi there, I've just started playing with D & am wondering about the in/out/inout parameters. Firstly - the documentation example of void foo(out int bar) { } int bar = 3; foo(bar); // bar is now 0 doesn't work :) bar is still 3. so for "out" bar isn't being initialised to 0. Next, because objects are passed by reference, is there anyway to make them "const"? Or is that an assertation using the design by contract? Cheers Brad
Nov 30 2003
brad beveridge wrote:Hi there, I've just started playing with D & am wondering about the in/out/inout parameters. Firstly - the documentation example of void foo(out int bar) { } int bar = 3; foo(bar); // bar is now 0 doesn't work :) bar is still 3. so for "out" bar isn't being initialised to 0.Although I see your point, I think that the current implementation makes sense. If the function does nothing, then really nothing should be done. I could see how people might argue otherwise, but it's really a coin toss what to do, IMHO.Next, because objects are passed by reference, is there anyway to make them "const"? Or is that an assertation using the design by contract?Walter has stated that he won't support const in function parameters because they are too problematic. They force a lot of weird rules on the language, apparently. (I don't remember his posts in enough detail to remember exactly what scenarios are problematic.) 'const', in D, is used only for global constants. It is a clue to the compiler that these variables are good ones to locate in the read-only section of the linked executable. (Thus, an attempt to write to them should cause a segmentation fault.)
Nov 30 2003