how to call ats function in c codes under dats file

41 views
Skip to first unread message

jin

unread,
Jun 23, 2025, 10:01:47 PMJun 23
to ats-lang-users
i'm using ats2, and i want to use pthread, i want to call ats funtion in c code, i tried the extern fun xxx="ext#xxx", but seems like c function cant use the xxx to run the ats function. any way to export a ats function with a global name which c can use?

jin

unread,
Jun 23, 2025, 10:28:27 PMJun 23
to ats-lang-users

fn exportToCTest (i:int):int=i+1

extern fun exportToCTest(i:int):int="ext#exportToCTest"

%{$
int callAtsTest(int a)
{
    return exportToCTest(0);
}
%}
here is my test code, cant run

jin

unread,
Jun 23, 2025, 10:35:26 PMJun 23
to ats-lang-users
extern fun exportToCTest(i:int):int="ext#exportToCTest"

implement exportToCTest (i)=i+1

%{$
int callAtsTest(int a)
{
    return exportToCTest(0);
}
%}
sorry, i forgot to use implement , its working now
在2025年6月24日星期二 UTC+8 10:01:47<jin> 写道:
Reply all
Reply to author
Forward
0 new messages