[Issue 10917] New: scope ref should be allowed
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Wed Aug 28 15:22:19 PDT 2013
http://d.puremagic.com/issues/show_bug.cgi?id=10917
Summary: scope ref should be allowed
Product: D
Version: D2
Platform: All
OS/Version: All
Status: NEW
Keywords: rejects-valid
Severity: normal
Priority: P2
Component: DMD
AssignedTo: nobody at puremagic.com
ReportedBy: andrej.mitrovich at gmail.com
--- Comment #0 from Andrej Mitrovic <andrej.mitrovich at gmail.com> 2013-08-28 15:22:18 PDT ---
-----
void foo(scope int* val) { } // ok
void bar(scope ref int val) { } // error
void main()
{
int x;
foo(&x); // ok
bar(x);
}
-----
'scope ref int' is almost the same thing as 'scope int*', except that 'ref'
cannot be null, and 'ref' is simpler to use in code since a user can copy by
value with the assignment syntax instead of having to dereference the pointer
first.
Note that addresses can be extracted from both pointers and references:
-----
int* ptr;
void foo(scope int* val)
{
ptr = val; // disallowed once scope is properly implemented
}
void bar(/*scope*/ ref int val)
{
ptr = &val; // equivalent to &main.x
}
void main()
{
int x;
foo(&x);
bar(x);
}
-----
So scope ref is very much useful to have.
And yeah, I realize scope does practically nothing in the compiler right now
(e.g.
http://forum.dlang.org/thread/rbgssjrzdcmbhxyhwlak@forum.dlang.org#post-mailman.391.1348770797.5162.digitalmars-d-learn:40puremagic.com).
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
More information about the Digitalmars-d-bugs
mailing list