digitalmars.D - Why isn't the array lenght property an lvalue?
- Jeroen Bollen (4/4) Apr 07 2014 When I have myarray.length, why isn't that considered an lvalue,
- Jeroen Bollen (2/7) Apr 07 2014 Well type would be ulong, so const(ulong)*
- MrSmith (2/10) Apr 07 2014 Array length is size_t which is uint on x86 and ulong on x86_64.
- Jeroen Bollen (2/13) Apr 07 2014 Alright, but why can't you get a pointer to it?
- MrSmith (3/18) Apr 07 2014 I've tried, but no luck here
- Andrei Alexandrescu (2/19) Apr 07 2014 This stuff is best moved to the learn forum. -- Andrei
- Steven Schveighoffer (4/21) Apr 07 2014 You had the elements backwards:
- MrSmith (4/30) Apr 07 2014 Cool! So, it is not a property function but actual size_t? How
- Steven Schveighoffer (5/7) Apr 07 2014 The array slice structure is a length followed by a pointer, your
- Iain Buclaw (4/37) Apr 08 2014 The compiler detects the pattern and invokes a runtime call to set the
- Justin Whear (3/8) Apr 07 2014 I believe `length` is implemented as a property function, though I can't...
- Jeroen Bollen (5/16) Apr 07 2014 Then you still should be able to get a pointer of the result. I
- Justin Whear (3/19) Apr 07 2014 Unless the length function returns by ref, the result is an rvalue and
- Jeroen Bollen (2/27) Apr 07 2014 Why doesn't it return by reference? Seems kinda dumb.
- Steven Schveighoffer (12/20) Apr 07 2014 It's a compiler builtin property. Reading simply returns the value from ...
When I have myarray.length, why isn't that considered an lvalue, and as a result, why cannot I get a pointer to it? It seems kinda dumb, I understand it cannot be changed manually, but surely you should be able to get a const(type)* from it?
Apr 07 2014
On Monday, 7 April 2014 at 19:13:31 UTC, Jeroen Bollen wrote:When I have myarray.length, why isn't that considered an lvalue, and as a result, why cannot I get a pointer to it? It seems kinda dumb, I understand it cannot be changed manually, but surely you should be able to get a const(type)* from it?Well type would be ulong, so const(ulong)*
Apr 07 2014
On Monday, 7 April 2014 at 19:23:45 UTC, Jeroen Bollen wrote:On Monday, 7 April 2014 at 19:13:31 UTC, Jeroen Bollen wrote:Array length is size_t which is uint on x86 and ulong on x86_64.When I have myarray.length, why isn't that considered an lvalue, and as a result, why cannot I get a pointer to it? It seems kinda dumb, I understand it cannot be changed manually, but surely you should be able to get a const(type)* from it?Well type would be ulong, so const(ulong)*
Apr 07 2014
On Monday, 7 April 2014 at 19:56:38 UTC, MrSmith wrote:On Monday, 7 April 2014 at 19:23:45 UTC, Jeroen Bollen wrote:Alright, but why can't you get a pointer to it?On Monday, 7 April 2014 at 19:13:31 UTC, Jeroen Bollen wrote:Array length is size_t which is uint on x86 and ulong on x86_64.When I have myarray.length, why isn't that considered an lvalue, and as a result, why cannot I get a pointer to it? It seems kinda dumb, I understand it cannot be changed manually, but surely you should be able to get a const(type)* from it?Well type would be ulong, so const(ulong)*
Apr 07 2014
On Monday, 7 April 2014 at 19:58:21 UTC, Jeroen Bollen wrote:On Monday, 7 April 2014 at 19:56:38 UTC, MrSmith wrote:I've tried, but no luck here http://dpaste.dzfl.pl/be526902ef4fOn Monday, 7 April 2014 at 19:23:45 UTC, Jeroen Bollen wrote:Alright, but why can't you get a pointer to it?On Monday, 7 April 2014 at 19:13:31 UTC, Jeroen Bollen wrote:Array length is size_t which is uint on x86 and ulong on x86_64.When I have myarray.length, why isn't that considered an lvalue, and as a result, why cannot I get a pointer to it? It seems kinda dumb, I understand it cannot be changed manually, but surely you should be able to get a const(type)* from it?Well type would be ulong, so const(ulong)*
Apr 07 2014
On 4/7/14, 1:30 PM, MrSmith wrote:On Monday, 7 April 2014 at 19:58:21 UTC, Jeroen Bollen wrote:This stuff is best moved to the learn forum. -- AndreiOn Monday, 7 April 2014 at 19:56:38 UTC, MrSmith wrote:I've tried, but no luck here http://dpaste.dzfl.pl/be526902ef4fOn Monday, 7 April 2014 at 19:23:45 UTC, Jeroen Bollen wrote:Alright, but why can't you get a pointer to it?On Monday, 7 April 2014 at 19:13:31 UTC, Jeroen Bollen wrote:Array length is size_t which is uint on x86 and ulong on x86_64.When I have myarray.length, why isn't that considered an lvalue, and as a result, why cannot I get a pointer to it? It seems kinda dumb, I understand it cannot be changed manually, but surely you should be able to get a const(type)* from it?Well type would be ulong, so const(ulong)*
Apr 07 2014
On Mon, 07 Apr 2014 16:30:13 -0400, MrSmith <mrsmith33 yandex.ru> wrote:On Monday, 7 April 2014 at 19:58:21 UTC, Jeroen Bollen wrote:You had the elements backwards: http://dpaste.dzfl.pl/8b5067aaf9d4 -SteveOn Monday, 7 April 2014 at 19:56:38 UTC, MrSmith wrote:I've tried, but no luck here http://dpaste.dzfl.pl/be526902ef4fOn Monday, 7 April 2014 at 19:23:45 UTC, Jeroen Bollen wrote:Alright, but why can't you get a pointer to it?On Monday, 7 April 2014 at 19:13:31 UTC, Jeroen Bollen wrote:Array length is size_t which is uint on x86 and ulong on x86_64.When I have myarray.length, why isn't that considered an lvalue, and as a result, why cannot I get a pointer to it? It seems kinda dumb, I understand it cannot be changed manually, but surely you should be able to get a const(type)* from it?Well type would be ulong, so const(ulong)*
Apr 07 2014
On Monday, 7 April 2014 at 20:43:09 UTC, Steven Schveighoffer wrote:On Mon, 07 Apr 2014 16:30:13 -0400, MrSmith <mrsmith33 yandex.ru> wrote:Cool! So, it is not a property function but actual size_t? How would it grow then?On Monday, 7 April 2014 at 19:58:21 UTC, Jeroen Bollen wrote:On Monday, 7 April 2014 at 19:56:38 UTC, MrSmith wrote:I've tried, but no luck here http://dpaste.dzfl.pl/be526902ef4fOn Monday, 7 April 2014 at 19:23:45 UTC, Jeroen Bollen wrote:Alright, but why can't you get a pointer to it?On Monday, 7 April 2014 at 19:13:31 UTC, Jeroen Bollen wrote:Array length is size_t which is uint on x86 and ulong on x86_64.When I have myarray.length, why isn't that considered an lvalue, and as a result, why cannot I get a pointer to it? It seems kinda dumb, I understand it cannot be changed manually, but surely you should be able to get a const(type)* from it?Well type would be ulong, so const(ulong)*You had the elements backwards: http://dpaste.dzfl.pl/8b5067aaf9d4 -Steve
Apr 07 2014
On Mon, 07 Apr 2014 17:18:09 -0400, MrSmith <mrsmith33 yandex.ru> wrote:Cool! So, it is not a property function but actual size_t? How would it grow then?The array slice structure is a length followed by a pointer, your structure was a pointer followed by a length. It still is a property function to set the length. -Steve
Apr 07 2014
On 7 April 2014 22:18, MrSmith <mrsmith33 yandex.ru> wrote:On Monday, 7 April 2014 at 20:43:09 UTC, Steven Schveighoffer wrote:The compiler detects the pattern and invokes a runtime call to set the new array length. If the new size is greater than the current allocated pool for the array, then it's realloc'd on the GC.On Mon, 07 Apr 2014 16:30:13 -0400, MrSmith <mrsmith33 yandex.ru> wrote:Cool! So, it is not a property function but actual size_t? How would it grow then?On Monday, 7 April 2014 at 19:58:21 UTC, Jeroen Bollen wrote:On Monday, 7 April 2014 at 19:56:38 UTC, MrSmith wrote:I've tried, but no luck here http://dpaste.dzfl.pl/be526902ef4fOn Monday, 7 April 2014 at 19:23:45 UTC, Jeroen Bollen wrote:Alright, but why can't you get a pointer to it?On Monday, 7 April 2014 at 19:13:31 UTC, Jeroen Bollen wrote:Array length is size_t which is uint on x86 and ulong on x86_64.When I have myarray.length, why isn't that considered an lvalue, and as a result, why cannot I get a pointer to it? It seems kinda dumb, I understand it cannot be changed manually, but surely you should be able to get a const(type)* from it?Well type would be ulong, so const(ulong)*
Apr 08 2014
On Mon, 07 Apr 2014 19:13:30 +0000, Jeroen Bollen wrote:When I have myarray.length, why isn't that considered an lvalue, and as a result, why cannot I get a pointer to it? It seems kinda dumb, I understand it cannot be changed manually, but surely you should be able to get a const(type)* from it?I believe `length` is implemented as a property function, though I can't find the source for the life of me.
Apr 07 2014
On Monday, 7 April 2014 at 20:12:48 UTC, Justin Whear wrote:On Mon, 07 Apr 2014 19:13:30 +0000, Jeroen Bollen wrote:Then you still should be able to get a pointer of the result. I was also considering it to be a property function, as indeed that'd explain this behaviour, but it still doesn't make sense to not allow it. After all, length is just a variable.When I have myarray.length, why isn't that considered an lvalue, and as a result, why cannot I get a pointer to it? It seems kinda dumb, I understand it cannot be changed manually, but surely you should be able to get a const(type)* from it?I believe `length` is implemented as a property function, though I can't find the source for the life of me.
Apr 07 2014
On Mon, 07 Apr 2014 20:14:13 +0000, Jeroen Bollen wrote:On Monday, 7 April 2014 at 20:12:48 UTC, Justin Whear wrote:Unless the length function returns by ref, the result is an rvalue and you won't be able to take a reference.On Mon, 07 Apr 2014 19:13:30 +0000, Jeroen Bollen wrote:Then you still should be able to get a pointer of the result. I was also considering it to be a property function, as indeed that'd explain this behaviour, but it still doesn't make sense to not allow it. After all, length is just a variable.When I have myarray.length, why isn't that considered an lvalue, and as a result, why cannot I get a pointer to it? It seems kinda dumb, I understand it cannot be changed manually, but surely you should be able to get a const(type)* from it?I believe `length` is implemented as a property function, though I can't find the source for the life of me.
Apr 07 2014
On Monday, 7 April 2014 at 20:19:30 UTC, Justin Whear wrote:On Mon, 07 Apr 2014 20:14:13 +0000, Jeroen Bollen wrote:Why doesn't it return by reference? Seems kinda dumb.On Monday, 7 April 2014 at 20:12:48 UTC, Justin Whear wrote:Unless the length function returns by ref, the result is an rvalue and you won't be able to take a reference.On Mon, 07 Apr 2014 19:13:30 +0000, Jeroen Bollen wrote:Then you still should be able to get a pointer of the result. I was also considering it to be a property function, as indeed that'd explain this behaviour, but it still doesn't make sense to not allow it. After all, length is just a variable.When I have myarray.length, why isn't that considered an lvalue, and as a result, why cannot I get a pointer to it? It seems kinda dumb, I understand it cannot be changed manually, but surely you should be able to get a const(type)* from it?I believe `length` is implemented as a property function, though I can't find the source for the life of me.
Apr 07 2014
On Mon, 07 Apr 2014 16:12:48 -0400, Justin Whear <justin economicmodeling.com> wrote:On Mon, 07 Apr 2014 19:13:30 +0000, Jeroen Bollen wrote:It's a compiler builtin property. Reading simply returns the value from inside the array (does not map to a property). Setting calls one of these two depending on the array type: https://github.com/D-Programming-Language/druntime/blob/master/src/rt/lifetime.d#L1282 https://github.com/D-Programming-Language/druntime/blob/master/src/rt/lifetime.d#L1460 The reason you can't get a pointer to it is that it's not a simple variable. Note, unlike C++, D does not allow you to get a const reference or pointer to an Rvalue. -SteveWhen I have myarray.length, why isn't that considered an lvalue, and as a result, why cannot I get a pointer to it? It seems kinda dumb, I understand it cannot be changed manually, but surely you should be able to get a const(type)* from it?I believe `length` is implemented as a property function, though I can't find the source for the life of me.
Apr 07 2014