Bug 7280 – Can't get address of array `.length` or `.ptr` properties

Status
RESOLVED
Resolution
WONTFIX
Severity
minor
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
Other
OS
Windows
Creation time
2012-01-12T09:06:00Z
Last change time
2012-01-12T10:17:01Z
Assigned to
nobody
Creator
verylonglogin.reg

Comments

Comment #0 by verylonglogin.reg — 2012-01-12T09:06:56Z
--- void f() { void[] arr; size_t* _length = &arr.length; // Error: arr.length is not an lvalue void** _ptr = &arr.ptr; // Error: cast(void*)arr is not an lvalue } --- What is the case not to behave like a struct of two elements? Workaround: --- size_t* arrayLengthRef(T)(ref T[] arr) { return (cast(size_t*)&arr); } T** arrayPtrRef(T)(ref T[] arr) { return (cast(T**)&arr) + 1; } ---
Comment #1 by schveiguy — 2012-01-12T10:17:01Z
arr.length is a read/write property. Writing length is not a simple field set, it calls a runtime function. arr.ptr is a read only property. Setting these must be done in tandem, and is done via the slicing interface or via the length set operation. You can circumvent as you say, but it should not be easy, since it is very dangerous.