# Interacting with C structs

**URL:** https://discourse.ats-lang.org/t/interacting-with-c-structs/134
**Category:** Google Group
**Created:** [September 6, 2014, 10:36pm UTC](https://discourse.ats-lang.org/t/interacting-with-c-structs/134 "2014-09-06T22:36:44Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Shea\_Levy](https://avatars.discourse-cdn.com/v4/letter/s/b38774/32.png) [@Shea\_Levy](https://discourse.ats-lang.org/u/Shea_Levy)
#### Post date: [September 6, 2014, 10:36pm UTC](https://discourse.ats-lang.org/t/interacting-with-c-structs/134/1 "2014-09-06T22:36:44Z")

</div>

Hi all,

I see in the tutorial that a C struct can be typedef’d with $extype, but  
I can’t seem to create a value of the type with record syntax. How am I  
meant to use extype?

~Shea

---

<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 6, 2014, 11:39pm UTC](https://discourse.ats-lang.org/t/interacting-with-c-structs/134/2 "2014-09-06T23:39:50Z")

</div>

A version without $UN.cast:

typedef Cint2 =  
$extype\_struct"struct{int x;int y;}" of { x= int, y= int }

implement  
main0 () =  
{  
//  
var xy: Cint2;  
val () = xy.x := 1  
val () = xy.y := 2  
//  
val () = println! ("xy.x = ", xy.x)  
val () = println! ("xy.y = ", xy.y)  
//  
} (\* end of [main0] \*)On Saturday, September 6, 2014 7:05:00 PM UTC-4, Brandon Barker wrote:

> This seems to compile:
> 
> staload UN = “prelude/SATS/unsafe.sats”
> 
> typedef Cint2 = $extype"struct{ int x; int y; }"
> 
> implement  
> main0 () =  
> {  
> val y = @(7, 3)  
> val x: Cint2 = $UN.cast{Cint2}{@(int,int)}(y)  
> }
> 
> Brandon Barker  
> [brand...@gmail.com](mailto:brand...@gmail.com) \<javascript:\>
> 
> On Sat, Sep 6, 2014 at 6:36 PM, Shea Levy \<[sh...@shealevy.com](mailto:sh...@shealevy.com) \<javascript:\>\> wrote:
> 
> > Hi all,
> > 
> > I see in the tutorial that a C struct can be typedef’d with $extype, but  
> > I can’t seem to create a value of the type with record syntax. How am I  
> > meant to use extype?
> > 
> > ~Shea
> > 
> > –  
> > You received this message because you are subscribed to the Google Groups  
> > “ats-lang-users” group.  
> > To unsubscribe from this group and stop receiving emails from it, send an  
> > email to [ats-lang...@googlegroups.com](mailto:ats-lang...@googlegroups.com) \<javascript:\>.  
> > To post to this group, send email to [ats-l...@googlegroups.com](mailto:ats-l...@googlegroups.com)  
> > \<javascript:\>.  
> > Visit this group at [http://groups.google.com/group/ats-lang-users](http://groups.google.com/group/ats-lang-users).  
> > To view this discussion on the web visit  
> > [https://groups.google.com/d/msgid/ats-lang-users/20140906223644.GA6613%40nixos.hsd1.nh.comcast.net](https://groups.google.com/d/msgid/ats-lang-users/20140906223644.GA6613%40nixos.hsd1.nh.comcast.net)  
> > .

---

<div class="post-metadata">

### Author: ![Brandon\_Barker](https://sea1.discourse-cdn.com/flex019/user_avatar/discourse.ats-lang.org/brandon_barker/32/61_2.png) [@Brandon\_Barker](https://discourse.ats-lang.org/u/Brandon_Barker)
#### Post date: [September 6, 2014, 11:04pm UTC](https://discourse.ats-lang.org/t/interacting-with-c-structs/134/3 "2014-09-06T23:04:39Z")

</div>

This seems to compile:

staload UN = “prelude/SATS/unsafe.sats”

typedef Cint2 = $extype"struct{ int x; int y; }"

implement  
main0 () =  
{  
val y = @(7, 3)  
val x: Cint2 = $UN.cast{Cint2}{@(int,int)}(y)  
}

Brandon Barker  
brandon…@gmail.comOn Sat, Sep 6, 2014 at 6:36 PM, Shea Levy [sh...@shealevy.com](mailto:sh...@shealevy.com) wrote:

> Hi all,
> 
> I see in the tutorial that a C struct can be typedef’d with $extype, but  
> I can’t seem to create a value of the type with record syntax. How am I  
> meant to use extype?
> 
> ~Shea
> 
> –  
> You received this message because you are subscribed to the Google Groups  
> “ats-lang-users” group.  
> To unsubscribe from this group and stop receiving emails from it, send an  
> email to [ats-lang-user...@googlegroups.com](mailto:ats-lang-user...@googlegroups.com).  
> To post to this group, send email to [ats-lan...@googlegroups.com](mailto:ats-lan...@googlegroups.com).  
> Visit this group at [http://groups.google.com/group/ats-lang-users](http://groups.google.com/group/ats-lang-users).  
> To view this discussion on the web visit  
> [https://groups.google.com/d/msgid/ats-lang-users/20140906223644.GA6613%40nixos.hsd1.nh.comcast.net](https://groups.google.com/d/msgid/ats-lang-users/20140906223644.GA6613%40nixos.hsd1.nh.comcast.net)  
> .
