arrays in srucs

Andy Balba pwplus7 at
Fri Jul 31 17:02:46 UTC 2020

I frequently use this paradigm for my image processing apps :

import std.stdio ;
struct S { int a, b; ubyte[] p;
void main()
{ S img= S(11,22) ;  img.p = new ubyte[5];

foreach (i; 0 .. 5) {
   img.p[i]=cast(ubyte)(10+i) ; printf(" sa %d sb %d : %d\n", 
img.a, img.b, img.p[i] );

The above code, compiles and runs ok  .. but sometimes I get run 
runtime errors using the same paradym, which disappear when I 
substitute (img.p)[i]

Any explanation for this ?

More information about the Digitalmars-d-learn mailing list