digitalmars.D.bugs - [Issue 1060] New: inout in arguments breaks the lvalueness of function
- d-bugmail puremagic.com Mar 13 2007
- d-bugmail puremagic.com Mar 13 2007
- d-bugmail puremagic.com Mar 14 2007
http://d.puremagic.com/issues/show_bug.cgi?id=1060 Summary: inout in arguments breaks the lvalueness of function Product: D Version: 1.009 Platform: PC OS/Version: Linux Status: NEW Severity: normal Priority: P2 Component: DMD AssignedTo: bugzilla digitalmars.com ReportedBy: gavrilyak gmail.com int[] foo(int[] arr){ return arr; } int[] boo(inout int[] arr){ return arr; } int[] arr = [1,2,3]; foo(foo(arr)); // ok boo(boo(arr)); // Error: boo(arr) is not an lvalue --
Mar 13 2007
http://d.puremagic.com/issues/show_bug.cgi?id=1060 fvbommel wxs.nl changed: What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |RESOLVED Resolution| |INVALID ------- Comment #1 from fvbommel wxs.nl 2007-03-13 17:30 ------- (In reply to comment #0)int[] foo(int[] arr){ return arr; } int[] boo(inout int[] arr){ return arr; } int[] arr = [1,2,3]; foo(foo(arr)); // ok boo(boo(arr)); // Error: boo(arr) is not an lvalue
Inout arguments don't "break" the lvalueness of a function. In fact, functions aren't lvalues, nor are their return values (which is presumably what you actually meant). The problem isn't that lvalueness is "broken", it's that an inout argument requires an lvalue to be passed and you're not doing it (in either case). Because of that, the second case doesn't work. The first one works fine because the parameter to foo isn't required to be an lvalue. Summary: the problem is in your code, not in the compiler or language. If this explanation isn't clear enough, please post a question about this in digitalmars.D.learn about this. Maybe someone there can explain it better. --
Mar 13 2007
http://d.puremagic.com/issues/show_bug.cgi?id=1060 gavrilyak gmail.com changed: What |Removed |Added ---------------------------------------------------------------------------- Status|RESOLVED |CLOSED ------- Comment #2 from gavrilyak gmail.com 2007-03-14 15:19 ------- Thanks for explanation, it's clear. That's how it's supposed to work and C++ works same way too, though it looks like premature optimization. For me semantics of those 2 snippets is the same int[] boo(inout int[] arr){ return arr; } int[] arr = [1,2,3]; //first - works int[] temp = boo(arr); boo(temp); //second boo(boo(arr)); May be D can be less restrictive then C++ and this issue is just a feature request :-). --
Mar 14 2007









d-bugmail puremagic.com 