digitalmars.D.learn - Creating a pointer array
- data pulverizer (15/15) Aug 19 2020 Hi all,
- Adam D. Ruppe (7/13) Aug 19 2020 I'd write it
- data pulverizer (4/18) Aug 19 2020 Argh, Sorry! The error was from the line before! False alarm. I
- data pulverizer (13/37) Aug 19 2020 For the record using:
- bachmeier (13/28) Aug 19 2020 Maybe I'm the only one, but I think double*[] is hideous, and I'd
- H. S. Teoh (18/25) Aug 19 2020 IMO, double*[] is absolutely logical. It's a natural consequence of type
- data pulverizer (13/26) Aug 19 2020 I know what you mean. I'm using something like this:
- data pulverizer (8/13) Aug 19 2020 Correction ...
- data pulverizer (15/29) Aug 22 2020 ... just realised,
Hi all, How do you create an array of pointers in D? I tried something like ``` double* []y; ``` Or ``` (double*) []y; ``` But I get the error: ``` Error: only one index allowed to index double[] ``` Thanks in advance.
Aug 19 2020
On Wednesday, 19 August 2020 at 13:03:54 UTC, data pulverizer wrote:How do you create an array of pointers in D? I tried something like ``` double* []y; ```I'd write it double*[] y; but yeah that's it.Error: only one index allowed to index double[]That must be at the usage point where you prolly just need parens or something.
Aug 19 2020
On Wednesday, 19 August 2020 at 13:08:37 UTC, Adam D. Ruppe wrote:On Wednesday, 19 August 2020 at 13:03:54 UTC, data pulverizer wrote:Argh, Sorry! The error was from the line before! False alarm. I was wandering why something so obvious wasn't working. Thanks anyway.How do you create an array of pointers in D? I tried something like ``` double* []y; ```I'd write it double*[] y; but yeah that's it.Error: only one index allowed to index double[]That must be at the usage point where you prolly just need parens or something.
Aug 19 2020
On Wednesday, 19 August 2020 at 13:12:21 UTC, data pulverizer wrote:On Wednesday, 19 August 2020 at 13:08:37 UTC, Adam D. Ruppe wrote:For the record using: ``` (double*)[] data; ``` gives an error ``` Error: found * when expecting . following double Error: found ) when expecting identifier following double. Error: found data when expecting ) ``` the other version was fine.On Wednesday, 19 August 2020 at 13:03:54 UTC, data pulverizer wrote:Argh, Sorry! The error was from the line before! False alarm. I was wandering why something so obvious wasn't working. Thanks anyway.How do you create an array of pointers in D? I tried something like ``` double* []y; ```I'd write it double*[] y; but yeah that's it.Error: only one index allowed to index double[]That must be at the usage point where you prolly just need parens or something.
Aug 19 2020
On Wednesday, 19 August 2020 at 13:03:54 UTC, data pulverizer wrote:Hi all, How do you create an array of pointers in D? I tried something like ``` double* []y; ``` Or ``` (double*) []y; ``` But I get the error: ``` Error: only one index allowed to index double[] ``` Thanks in advance.Maybe I'm the only one, but I think double*[] is hideous, and I'd sure hate for someone not used to D to see it. Alias is your friend. I think this is much nicer: void main() { alias double* DoublePtr; DoublePtr[] arr; auto v = [1.0, 2.0, 3.0]; auto w = [4.0, 5.0, 6.0]; arr ~= [v.ptr, w.ptr]; writeln(arr); }
Aug 19 2020
On Wed, Aug 19, 2020 at 08:09:31PM +0000, bachmeier via Digitalmars-d-learn wrote: [...]Maybe I'm the only one, but I think double*[] is hideous, and I'd sure hate for someone not used to D to see it.IMO, double*[] is absolutely logical. It's a natural consequence of type syntax.Alias is your friend. I think this is much nicer: void main() { alias double* DoublePtr; DoublePtr[] arr;[...] IMO, this is far too verbose. If I had 10 arrays of 10 different types of pointers, I wouldn't want to write 10 aliases just for that. Plus, hiding things behind an alias means someone who reads your code has to look up the alias definition to figure out what it means, whereas if they see double*[] the exact meaning is immediately obvious. I'd only use an alias for inordinately-long type names, like function pointers or delegates with lots of parameters, or verbose type names like const(int[])[string]. (And even in the latter case, only when the name occurs frequently.) But as they say, YMMV. :-) T -- "A man's wife has more power over him than the state has." -- Ralph Emerson
Aug 19 2020
On Wednesday, 19 August 2020 at 20:09:31 UTC, bachmeier wrote:On Wednesday, 19 August 2020 at 13:03:54 UTC, data pulverizer wrote: Maybe I'm the only one, but I think double*[] is hideous, and I'd sure hate for someone not used to D to see it. Alias is your friend. I think this is much nicer: void main() { alias double* DoublePtr; DoublePtr[] arr; auto v = [1.0, 2.0, 3.0]; auto w = [4.0, 5.0, 6.0]; arr ~= [v.ptr, w.ptr]; writeln(arr); }I know what you mean. I'm using something like this: ``` alias P(T) = T*; P!(double)[] arr; ``` alias is one of those awesome chameleons in D. The template equivalent is ``` template P(T) = T*; ``` In this case I wonder if there is any difference as far as the compiler is concerned?
Aug 19 2020
On Wednesday, 19 August 2020 at 21:10:00 UTC, data pulverizer wrote:alias is one of those awesome chameleons in D. The template equivalent is ``` template P(T) = T*; ```Correction ... ``` template P(T){ alias P = T*; } ```
Aug 19 2020
On Wednesday, 19 August 2020 at 22:21:21 UTC, data pulverizer wrote:On Wednesday, 19 August 2020 at 21:10:00 UTC, data pulverizer wrote:... just realised, ``` alias P(T) = T*; ``` Is just shorthand for ... ``` template P(T) { alias P = T*; } ``` Just as functions, classes, structs, and enums have template shorthands. Lol!alias is one of those awesome chameleons in D. The template equivalent is ``` template P(T) = T*; ```Correction ... ``` template P(T){ alias P = T*; } ```
Aug 22 2020