digitalmars.D - How to define syscall() in freebsd?
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); extern (C) nothrow nogc size_t syscall(size_t ident, long* 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) 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
Jul 12 2018
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: syscallJust 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: 100567Probably related to first issue mentioned- you cannot overload C functions- maybe the compiler finds the third now that you removed the disallowed overloads.
Jul 12 2018
On Thursday, 12 July 2018 at 15:45:41 UTC, Joakim wrote:On Thursday, 12 July 2018 at 13:55:58 UTC, Brian wrote: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?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: syscallJust 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: 100567Probably related to first issue mentioned- you cannot overload C functions- maybe the compiler finds the third now that you removed the disallowed overloads.
Jul 12 2018
On Thursday, 12 July 2018 at 20:19:17 UTC, Brian wrote:freebsd syscall() https://www.freebsd.org/cgi/man.cgi?query=syscall&sektion=2 How to define it in D?It should be fine like this: extern (C) nothrow nogc size_t syscall(size_t ident, ...);
Jul 12 2018
On Friday, 13 July 2018 at 02:56:23 UTC, Heromyth wrote:On Thursday, 12 July 2018 at 20:19:17 UTC, Brian wrote:hahaha, thanks MR zhang! kiss.sys.syscall module is resolved. https://github.com/huntlabs/kiss/blob/master/source/kiss/sys/syscall/package.dfreebsd syscall() https://www.freebsd.org/cgi/man.cgi?query=syscall&sektion=2 How to define it in D?It should be fine like this: extern (C) nothrow nogc size_t syscall(size_t ident, ...);
Jul 13 2018