Interacting with C structs

32 views
Skip to first unread message

Shea Levy

unread,
Sep 6, 2014, 6:37:05 PM9/6/14
to ats-lan...@googlegroups.com
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

Brandon Barker

unread,
Sep 6, 2014, 7:05:00 PM9/6/14
to ats-lang-users
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.com



~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.
To post to this group, send email to ats-lan...@googlegroups.com.
Visit this group at 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.

gmhwxi

unread,
Sep 6, 2014, 7:39:50 PM9/6/14
to ats-lan...@googlegroups.com
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] *)

Reply all
Reply to author
Forward
0 new messages