Looks like explicitly initialized variable in this case allocates
array literal. Uninitialized variable is initialized with init
pattern. This may be correct as uninitialized variable isn't
guaranteed to hold a value most useful for you, it's only
guaranteed to hold a defined value.
On Wednesday, 26 October 2022 at 04:40:17 UTC, Salih Dincer wrote:
On Tuesday, 25 October 2022 at 13:51:30 UTC, Andrey Zherikov
wrote:
Does the second piece of code shows a bug or my expectation is
not correct (and why if so)?
As a result, if this is a bug, Andrey has the right to report
it.
On Wednesday, 26 October 2022 at 02:34:24 UTC, Ali Çehreli wrote:
On 10/25/22 19:25, Salih Dincer wrote:
> with static in main():
If 'static' makes a difference on your side as well, it is your
turn to create a bug report. :) (Last time you discovered a
bug, I was too quick to report it. :/)
On 10/25/22 19:25, Salih Dincer wrote:
> with static in main():
If 'static' makes a difference on your side as well, it is your turn to
create a bug report. :) (Last time you discovered a bug, I was too quick
to report it. :/)
Ali
On Wednesday, 26 October 2022 at 00:44:45 UTC, H. S. Teoh wrote:
If you'll excuse some ASCII art, here's the situation you have:
STACK GLOBAL DATA
x[0] {
Y[] y; -+> [ Y.init ]
} |
x[1] { |
On 10/25/22 17:16, Salih Dincer wrote:
> Excuse me, but they still write in purple prose about dynamic
> array literature here!
I've heard positive things about D's arrays from people who use D in
production. Especially slices...
> I've known D for more than 10 years, but the topic we're
On Wed, Oct 26, 2022 at 12:16:55AM +, Salih Dincer via Digitalmars-d-learn
wrote:
[...]
> I've known D for more than 10 years, but the topic we're talking about
> still seems strange to me. The explanations given are not enough for
> me, I'm sorry.
>
> Can anyone tell me what happens when I
On Tuesday, 25 October 2022 at 20:36:28 UTC, matheus wrote:
On
int[] a = [1];
int[] b = a.dup;
assert([0] !is [0]); // different memory
```
This is interesting, I understand the point of "reference vs
copy", and I'm OK with this design choice of, but I wonder in
the case of newcomers if
On 10/25/22 13:36, matheus wrote:
> On Tuesday, 25 October 2022 at 20:12:25 UTC, Paul Backus wrote:
>> Static arrays are value types.
What that means is, when we say float[3], there are just 3 floats
without any overhead.
>> Dynamic arrays are reference types.
That phrase can be confusing
On Tuesday, 25 October 2022 at 20:27:18 UTC, Ali Çehreli wrote:
On 10/25/22 13:12, Paul Backus wrote:
> In order to create a copy of a static array
Although .dup works for static arrays as well, you meant
"dynamic array" and everyones knows it. :)
Yes; thank you for the correction. :)
On Tuesday, 25 October 2022 at 20:12:25 UTC, Paul Backus wrote:
On Tuesday, 25 October 2022 at 17:54:16 UTC, Salih Dincer wrote:
On Tuesday, 25 October 2022 at 17:18:35 UTC, Paul Backus wrote:
It's not a bug. They're pointing to the exact same instance
of `A` in memory:
I don't understand?
On 10/25/22 13:12, Paul Backus wrote:
> In order to create a copy of a static array
Although .dup works for static arrays as well, you meant "dynamic array"
and everyones knows it. :)
> with its own block of
> memory, separate from the original, you have to use the built-in `.dup`
> method:
On Tuesday, 25 October 2022 at 17:54:16 UTC, Salih Dincer wrote:
On Tuesday, 25 October 2022 at 17:18:35 UTC, Paul Backus wrote:
It's not a bug. They're pointing to the exact same instance of
`A` in memory:
I don't understand? So I don't understand why it causes
problems with dynamic
On 10/25/22 11:23, Steven Schveighoffer wrote:
>> Why do I say incorrect things like that? :)
> You were right actually.
As always! Now I'm confused. :o)
Ali
On 10/25/22 2:03 PM, Ali Çehreli wrote:
On 10/25/22 11:01, Ali Çehreli wrote:
> static arrays don't have .ptr to point
> to any member.
Why do I say incorrect things like that? :) Of course static arrays have
.ptr as well but that always point to their own body of N elements. They
own
On 10/25/22 11:01, Ali Çehreli wrote:
> static arrays don't have .ptr to point
> to any member.
Why do I say incorrect things like that? :) Of course static arrays have
.ptr as well but that always point to their own body of N elements. They
own their elements... I move away from the keyboard
On 10/25/22 10:54, Salih Dincer wrote:
> So I don't understand why it causes problems with
> dynamic arrays! So why is there nothing wrong with the static array in
> the example below?
The same rules as other uses of dynamic arrays...
> //A[] a = [A.init];/*
In that case, there is a
On Tuesday, 25 October 2022 at 17:18:35 UTC, Paul Backus wrote:
It's not a bug. They're pointing to the exact same instance of
`A` in memory:
I don't understand? So I don't understand why it causes problems
with dynamic arrays! So why is there nothing wrong with the
static array in the
On 10/25/22 08:50, Andrey Zherikov wrote:
> I'd like to tune default ctor but structs can't have custom one.
> Adding a ctor with parameter seems a hack to me
There is static opCall, which may be seen as a hack as well. :) The
following all print the same thing now:
import std.stdio;
struct
On Tuesday, 25 October 2022 at 16:52:48 UTC, Salih Dincer wrote:
On Tuesday, 25 October 2022 at 13:51:30 UTC, Andrey Zherikov
wrote:
Does the second piece of code shows a bug or my expectation is
not correct (and why if so)?
This is a bug:
```d
void main()
{
struct B
{
struct A
{
On Tuesday, 25 October 2022 at 13:51:30 UTC, Andrey Zherikov
wrote:
Does the second piece of code shows a bug or my expectation is
not correct (and why if so)?
This is a bug:
```d
void main()
{
struct B
{
struct A
{
int i = 10;
}
A[] a = [A.init];
}
B[2] b;
On Tuesday, 25 October 2022 at 14:53:50 UTC, Adam D Ruppe wrote:
On Tuesday, 25 October 2022 at 13:51:30 UTC, Andrey Zherikov
wrote:
A[] a = [A.init];
This is a problem - this is referring to a static array
instance, shared across all copies of B. You almost certainly
don't want this.
On Tuesday, 25 October 2022 at 14:53:50 UTC, Adam D Ruppe wrote:
But just don't do this. Only basic values and immutable strings
are good to initialize this way. With the array or class
objects, you're liable to get some shared thing.
If you change this to be initialized in a constructor
On 10/25/22 07:53, Adam D Ruppe wrote:
> On Tuesday, 25 October 2022 at 13:51:30 UTC, Andrey Zherikov wrote:
>> A[] a = [A.init];
>
> This is a problem - this is referring to a static array instance, shared
> across all copies of B. You almost certainly don't want this.
Agreed. It should be
On Tuesday, 25 October 2022 at 13:51:30 UTC, Andrey Zherikov
wrote:
A[] a = [A.init];
This is a problem - this is referring to a static array instance,
shared across all copies of B. You almost certainly don't want
this.
That B.a[0] is the *same object* across different
25 matches
Mail list logo