Re: How to represent struct with trailing array member

2016-01-22 Thread userABCabc123 via Digitalmars-d-learn
On Friday, 22 January 2016 at 08:39:06 UTC, Dibyendu Majumdar wrote: On Friday, 22 January 2016 at 01:53:53 UTC, Chris Wright wrote: On Thu, 21 Jan 2016 21:52:06 +, Dibyendu Majumdar wrote: Hi I have C code where the struct has a trailing array member: struct matrix { int rows;

Re: How to represent struct with trailing array member

2016-01-22 Thread Dibyendu Majumdar via Digitalmars-d-learn
On Friday, 22 January 2016 at 01:53:53 UTC, Chris Wright wrote: On Thu, 21 Jan 2016 21:52:06 +, Dibyendu Majumdar wrote: Hi I have C code where the struct has a trailing array member: struct matrix { int rows; int cols; double data[1]; }; D has bounds checking, which makes this

How to represent struct with trailing array member

2016-01-21 Thread Dibyendu Majumdar via Digitalmars-d-learn
Hi I have C code where the struct has a trailing array member: struct matrix { int rows; int cols; double data[1]; }; In C code this is allocated dynamically to be variable size. The array is used just as normal. How should this be translated to D? Will D's array access allow data

Re: How to represent struct with trailing array member

2016-01-21 Thread bearophile via Digitalmars-d-learn
Dibyendu Majumdar: On Thursday, 21 January 2016 at 21:52:06 UTC, Dibyendu Majumdar wrote: How should this be translated to D? Will D's array access allow data elements to be accessed beyond the size declared? Take a look at the code I've written here:

Re: How to represent struct with trailing array member

2016-01-21 Thread Chris Wright via Digitalmars-d-learn
On Thu, 21 Jan 2016 21:52:06 +, Dibyendu Majumdar wrote: > Hi > > I have C code where the struct has a trailing array member: > > struct matrix { >int rows; >int cols; >double data[1]; > }; > > In C code this is allocated dynamically to be variable size. The array > is used