digitalmars.D - Explicit conversion needed to go from array to pointer??
- Henrik Harmsen (8/8) Feb 22 2007 I'm looking at the D reference manual in the "arrays" section. It says u...
- Leandro Lucarella (6/17) Feb 22 2007 The manual is wrong, this was deprecated not too long ago.
- Henrik Harmsen (8/27) Feb 22 2007 Oh..
- Jarrett Billingsley (6/8) Feb 22 2007 Made illegal. There were too many "gotchas" when passing arrays to C
- Stewart Gordon (5/11) Feb 22 2007 Effectively, obsolete but not yet illegal. Code that uses deprecated fe...
- Xinok (4/38) Feb 22 2007 The best way I can find is to:
I'm looking at the D reference manual in the "arrays" section. It says under "usage": int* p; int[3] s; p = s; // p points to the first element of the array s. But when I try this I get: "cannot implicitly convert expression (s) of type int[3] to int*." Why? Is the manual wrong or the compiler or what am I missing? -- Henrik (newbie)
Feb 22 2007
Henrik Harmsen escribió:I'm looking at the D reference manual in the "arrays" section. It says under "usage": int* p; int[3] s; p = s; // p points to the first element of the array s. But when I try this I get: "cannot implicitly convert expression (s) of type int[3] to int*." Why? Is the manual wrong or the compiler or what am I missing?The manual is wrong, this was deprecated not too long ago. -- Leandro Lucarella Integratech S.A. 4571-5252
Feb 22 2007
Leandro Lucarella Wrote:Henrik Harmsen escribió:Oh.. Deprecated in what way? Made illegal or obsolete or..? Can I use an explicit cast? Will it work? Like this: p = cast(int*)s; // p points to the first element of the array s. ? -- HenrikI'm looking at the D reference manual in the "arrays" section. It says under "usage": int* p; int[3] s; p = s; // p points to the first element of the array s. But when I try this I get: "cannot implicitly convert expression (s) of type int[3] to int*." Why? Is the manual wrong or the compiler or what am I missing?The manual is wrong, this was deprecated not too long ago. -- Leandro Lucarella Integratech S.A. 4571-5252
Feb 22 2007
"Henrik Harmsen" <henrik harmsen.se> wrote in message news:erka4u$2e0n$1 digitalmars.com...Deprecated in what way? Made illegal or obsolete or..?Made illegal. There were too many "gotchas" when passing arrays to C functions (which is really the only time this conversion was used).Can I use an explicit cast? Will it work?You can just use the .ptr property of the array: char* p = s.ptr;
Feb 22 2007
Henrik Harmsen Wrote: <snip>Deprecated in what way? Made illegal or obsolete or..?Effectively, obsolete but not yet illegal. Code that uses deprecated features can still be compiled using the -d compiler option.Can I use an explicit cast? Will it work? Like this: p = cast(int*)s; // p points to the first element of the array s. ?You could, but perhaps nicer is to just use the .ptr property. Stewart.
Feb 22 2007
Henrik Harmsen wrote:Leandro Lucarella Wrote:The best way I can find is to: p = &s[0]; Or as others have said, just use the .ptr property.Henrik Harmsen escribió:Oh.. Deprecated in what way? Made illegal or obsolete or..? Can I use an explicit cast? Will it work? Like this: p = cast(int*)s; // p points to the first element of the array s. ? -- HenrikI'm looking at the D reference manual in the "arrays" section. It says under "usage": int* p; int[3] s; p = s; // p points to the first element of the array s. But when I try this I get: "cannot implicitly convert expression (s) of type int[3] to int*." Why? Is the manual wrong or the compiler or what am I missing?The manual is wrong, this was deprecated not too long ago. -- Leandro Lucarella Integratech S.A. 4571-5252
Feb 22 2007