# Unbox array @ doesn't construct memory. It causes SEGV. (#90)

**URL:** <https://discourse.ats-lang.org/t/unbox-array-doesnt-construct-memory-it-causes-segv-90/542>\
**Category:** Google Group\
**Created:** [September 16, 2014, 5:39am UTC](https://discourse.ats-lang.org/t/unbox-array-doesnt-construct-memory-it-causes-segv-90/542 "2014-09-16T05:39:32Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![gmhwxi](https://avatars.discourse-cdn.com/v4/letter/g/67e7ee/32.png) [@gmhwxi](https://discourse.ats-lang.org/u/gmhwxi)\
**Post date:** [September 16, 2014, 5:39am UTC](https://discourse.ats-lang.org/t/unbox-array-doesnt-construct-memory-it-causes-segv-90/542/1 "2014-09-16T05:39:32Z")

</div>

It causes SEGV. (#90)  
[reply+i-42844433-1baf5a9942cb121...@reply.github.com](mailto:reply+i-42844433-1baf5a9942cb121...@reply.github.com)

> 

Mapping ATS types to C types can be difficult, sometimes.

I suggest the following approach:

%{^  
typedef  
struct {  
int m0;  
int m1[128];  
int m2[128];  
} mystruct;  
%}

typedef  
mystruct =  
$extype\_struct"mystruct"of{  
m0 = int, m1 = @[int][128], m2= @[int][128]  
}On Tue, Sep 16, 2014 at 12:57 AM, Kiwamu Okabe [notifi...@github.com](mailto:notifi...@github.com) wrote:

> I think following should be also available…
> 
> #include “share/atspre\_define.hats”  
> #include “share/atspre\_staload.hats”
> 
> vtypedef mystruct = @{  
> m0 = int  
> , m1 = @[int][128]  
> , m2 = @[int][128]  
> }
> 
> implement main0 () = {  
> var stA: mystruct  
> }
> 
> $ patscc main.dats  
> exec(patsopt --output main\_dats.c --dynamic main.dats)  
> exec(patsopt --output main\_dats.c --dynamic main.dats) = 0  
> exec(gcc -std=c99 -D\_XOPEN\_SOURCE -I${PATSHOME} -I${PATSHOME}/ccomp/runtime -L${PATSHOME}/ccomp/atslib/lib -L${PATSHOME}/ccomp/atslib/lib64 main\_dats.c)  
> main\_dats.c:211:29: error: flexible array member not at end of struct  
> atstkind\_t0ype(atstype\_int) atslab\_\_m1;  
> ^  
> exec(gcc -std=c99 -D\_XOPEN\_SOURCE -I${PATSHOME} -I${PATSHOME}/ccomp/runtime -L${PATSHOME}/ccomp/atslib/lib -L${PATSHOME}/ccomp/atslib/lib64 main\_dats.c) = 256
> 
> —  
> Reply to this email directly or view it on GitHub  
> [https://github.com/githwxi/ATS-Postiats/issues/90#issuecomment-55695859](https://github.com/githwxi/ATS-Postiats/issues/90#issuecomment-55695859).
