www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Convert array of simple structs, to C array of values

reply Chris Katko <ckatko gmail.com> writes:
```D
struct pair
   {
   float x;
   float y;
   }

pair[10] values;
import std.conv;
auto valuesInCStyle = to!(const float*)(values);

```

Now that's not going to work because (I would imagine) to! 
doesn't understand x, and y, can be placed in order to give an 
array of:

valuesInCStyle = [values[0].x, values[0].y, values[1].x 
,values[1].y, ...]

I know there's gotta be some simple one liner function in D, but 
I can't think of it.
Oct 03 2022
parent Dennis <dkorpel gmail.com> writes:
On Monday, 3 October 2022 at 07:45:47 UTC, Chris Katko wrote:
 I know there's gotta be some simple one liner function in D, 
 but I can't think of it.
I don't know if you're looking for type safety, but you can just do `cast(float*) values.ptr;` or `cast(float[]) values[]`.
Oct 03 2022