On Thursday, 12 July 2018 at 15:45:41 UTC, Joakim wrote:
On Thursday, 12 July 2018 at 13:55:58 UTC, Brian wrote:
the code is error:
extern (C) nothrow @nogc size_t syscall(size_t ident);
extern (C) nothrow @nogc size_t syscall(size_t ident, size_t arg0); extern (C) nothrow @nogc size_t syscall(size_t ident, long* arg0);

long tid;
syscall(SYS_thr_self, &tid);
writeln(tid);

Error: Function type does not match previously declared function with the same mangled name: syscall

Just like in C, you cannot declare multiple extern(C) functions with the same name.

Change to:
extern (C) nothrow @nogc size_t syscall(size_t ident);
extern (C) nothrow @nogc size_t syscall(size_t ident, size_t arg0); extern (C) nothrow @nogc size_t syscall(size_t ident, long* arg0);

long tid;
syscall(SYS_thr_self, &tid);
writeln(tid);

What did you change? I see no difference.

Error: none of the overloads of syscall are callable using argument types (int, long*), candidates are: source/app.d(3,33): kiss.sys.syscall.syscall(ulong ident) source/app.d(4,33): kiss.sys.syscall.syscall(ulong ident, ulong arg0)

Look at the types: the error says you're passing an int and long* on 64-bit to functions with different types.

Change to:
// extern (C) nothrow @nogc size_t syscall(size_t ident);
// extern (C) nothrow @nogc size_t syscall(size_t ident, size_t arg0); extern (C) nothrow @nogc size_t syscall(size_t ident, long* arg0);

long tid;
syscall(SYS_thr_self, &tid);
writeln(tid);

result:

100567

Probably related to first issue mentioned- you cannot overload C functions- maybe the compiler finds the third now that you removed the disallowed overloads.

I'm sorry, downstairs:
the code is error:
extern (C) nothrow @nogc size_t syscall(size_t ident);
extern (C) nothrow @nogc size_t syscall(size_t ident, size_t arg0);
extern (C) nothrow @nogc size_t syscall(size_t ident, long* arg0);

long tid;
syscall(SYS_thr_self, &tid);
writeln(tid);

Error: Function type does not match previously declared function with the same mangled name: syscall


Change to:
extern (C) nothrow @nogc size_t syscall(size_t ident);
extern (C) nothrow @nogc size_t syscall(size_t ident, size_t arg0);

long tid;
syscall(SYS_thr_self, &tid);
writeln(tid);

Error: none of the overloads of syscall are callable using argument types (int, long*), candidates are:
source/app.d(3,33):        kiss.sys.syscall.syscall(ulong ident)
source/app.d(4,33): kiss.sys.syscall.syscall(ulong ident, ulong arg0)

freebsd syscall()
https://www.freebsd.org/cgi/man.cgi?query=syscall&sektion=2

How to define it in D?

Reply via email to