22-Mar-2013 13:01, Jacob Carlborg пишет:
On 2013-03-22 09:14, Dmitry Olshansky wrote:

OK so c points to [1, 2, 3, 4, 5] (and who knows if it's 5 bytes or 5
ints) slice. *c is that slice, (cast(int[])*c)[1..3] is pieces of that
slice an r-value.
Mmm so you are returning a pointer to r-value (a local temporary)?
What's the point of the code?

I'm showing here a reduced minimal test case, that's why it looks
strange. The full source code is here:


It doesn't change the fact that pointer to slice is not going to work. Esp pointer to stack-allocated slice. You'll get garbage and sometimes segfaults.

What's wrong with returning slice by value ?

https://github.com/jacob-carlborg/orange/blob/master/orange/serialization/Serializer.d#L1672

Exactly what you describe there is not going to work at all. Taking address of temporary slice (a[x..y] is a temporary value) is welcoming a segfault.



--
Dmitry Olshansky

Reply via email to