Thread overview | ||||||
---|---|---|---|---|---|---|
|
March 13, 2007 [Issue 1060] New: inout in arguments breaks the lvalueness of function | ||||
---|---|---|---|---|
| ||||
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 -- |
March 13, 2007 [Issue 1060] inout in arguments breaks the lvalueness of function | ||||
---|---|---|---|---|
| ||||
Posted in reply to d-bugmail | 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. -- |
March 14, 2007 [Issue 1060] inout in arguments breaks the lvalueness of function | ||||
---|---|---|---|---|
| ||||
Posted in reply to d-bugmail | 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 :-). -- |
January 26, 2013 [Issue 1060] inout in arguments breaks the lvalueness of function | ||||
---|---|---|---|---|
| ||||
Posted in reply to d-bugmail | 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: ------- |
Copyright © 1999-2021 by the D Language Foundation