digitalmars.D.bugs - [Issue 1060] New: inout in arguments breaks the lvalueness of function
- d-bugmail puremagic.com (22/22) Mar 13 2007 http://d.puremagic.com/issues/show_bug.cgi?id=1060
- d-bugmail puremagic.com (19/31) Mar 13 2007 http://d.puremagic.com/issues/show_bug.cgi?id=1060
- d-bugmail puremagic.com (21/21) Mar 14 2007 http://d.puremagic.com/issues/show_bug.cgi?id=1060
- d-bugmail puremagic.com (9/9) Jan 26 2013 http://d.puremagic.com/issues/show_bug.cgi?id=1060
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| |INVALIDint[] 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 lvalueInout 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 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
http://d.puremagic.com/issues/show_bug.cgi?id=1060 Andrei Alexandrescu <andrei erdani.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|CLOSED |RESOLVED CC| |andrei erdani.com -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Jan 26 2013