Re: Call a function with a function pointer

2013-10-13 Thread Benjamin Thaut
Am 13.10.2013 17:17, schrieb Artur Skawina: On 10/13/13 16:43, Benjamin Thaut wrote: Am 10.10.2013 17:45, schrieb Namespace: On Thursday, 10 October 2013 at 15:15:45 UTC, bearophile wrote: Namespace: You mean like this? void foo(T)(extern(C) void function(T*) func) { } That print

Re: Call a function with a function pointer

2013-10-13 Thread Artur Skawina
On 10/13/13 16:43, Benjamin Thaut wrote: > Am 10.10.2013 17:45, schrieb Namespace: >> On Thursday, 10 October 2013 at 15:15:45 UTC, bearophile wrote: >>> Namespace: >>> You mean like this? void foo(T)(extern(C) void function(T*) func) { } That print

Re: Call a function with a function pointer

2013-10-13 Thread Benjamin Thaut
Am 10.10.2013 17:45, schrieb Namespace: On Thursday, 10 October 2013 at 15:15:45 UTC, bearophile wrote: Namespace: You mean like this? void foo(T)(extern(C) void function(T*) func) { } That prints: Error: basic type expected, not extern In theory that's correct, in practice the c

Re: Call a function with a function pointer

2013-10-11 Thread Dicebot
On Friday, 11 October 2013 at 15:55:17 UTC, Artur Skawina wrote: It's probably not just "incompetence" (the compiler is able to figure this out in other contexts), but a deliberate choice. Having function types depend on their bodies would not be a good idea. Eg int c; auto f() {

Re: Call a function with a function pointer

2013-10-11 Thread Artur Skawina
On 10/10/13 20:54, Dicebot wrote: > On Thursday, 10 October 2013 at 17:47:54 UTC, Namespace wrote: >> >> import std.stdio; >> >> void foo1(void function(void*) fp) { } >> void foo2(void function(int) fp) { } >> void foo3(void*) { } >> >> void main() >> { >> foo1((void* ptr) => ( assert(ptr

Re: Call a function with a function pointer

2013-10-10 Thread bearophile
Andrej Mitrovic: I'm pretty sure I saw it filed somewhere. Can't find it though.. I have just added the new test case :-) http://d.puremagic.com/issues/show_bug.cgi?id=6754 Bye, bearophile

Re: Call a function with a function pointer

2013-10-10 Thread Andrej Mitrovic
On 10/10/13, bearophile wrote: > Perhaps this bug is not yet in Bugzilla. I'm pretty sure I saw it filed somewhere. Can't find it though..

Re: Call a function with a function pointer

2013-10-10 Thread Dicebot
On Thursday, 10 October 2013 at 17:47:54 UTC, Namespace wrote: import std.stdio; void foo1(void function(void*) fp) { } void foo2(void function(int) fp) { } void foo3(void*) { } void main() { foo1((void* ptr) => ( assert(ptr is null) )); foo2((int a) => ( a + 1 )); /// Fails: Erro

Re: Call a function with a function pointer

2013-10-10 Thread Namespace
import std.stdio; void foo1(void function(void*) fp) { } void foo2(void function(int) fp) { } void foo3(void*) { } void main() { foo1((void* ptr) => ( assert(ptr is null) )); foo2((int a) => ( a + 1 )); /// Fails: Error: function foo2 (void function(int) fp) is not callable using

Re: Call a function with a function pointer

2013-10-10 Thread bearophile
Namespace: /d917/f732.d(8): Error: basic type expected, not extern /d917/f732.d(8): Error: semicolon expected to close alias declaration /d917/f732.d(8): Error: no identifier for declarator void function(T*) It seems that even the new alias syntax doesn't support the extern :-) Perhaps this

Re: Call a function with a function pointer

2013-10-10 Thread Dicebot
On Thursday, 10 October 2013 at 15:15:45 UTC, bearophile wrote: Namespace: You mean like this? void foo(T)(extern(C) void function(T*) func) { } That prints: Error: basic type expected, not extern In theory that's correct, in practice the compiler refuses tha

Re: Call a function with a function pointer

2013-10-10 Thread Namespace
On Thursday, 10 October 2013 at 15:15:45 UTC, bearophile wrote: Namespace: You mean like this? void foo(T)(extern(C) void function(T*) func) { } That prints: Error: basic type expected, not extern In theory that's correct, in practice the compiler refuses tha

Re: Call a function with a function pointer

2013-10-10 Thread Namespace
On Thursday, 10 October 2013 at 14:44:00 UTC, Dicebot wrote: On Thursday, 10 October 2013 at 14:40:09 UTC, Namespace wrote: Example? I do not use lambdas often. void foo(T)(void function(T*) test) { } extern(C) void bar(int*) { } void main() { foo( (int* a) => bar(a) ); } I don't kn

Re: Call a function with a function pointer

2013-10-10 Thread bearophile
Namespace: You mean like this? void foo(T)(extern(C) void function(T*) func) { } That prints: Error: basic type expected, not extern In theory that's correct, in practice the compiler refuses that, it's in Bugzilla, so try to define the type outside the signat

Re: Call a function with a function pointer

2013-10-10 Thread Namespace
On Thursday, 10 October 2013 at 14:28:20 UTC, Dicebot wrote: On Thursday, 10 October 2013 at 14:13:47 UTC, Namespace wrote: I have this function: void foo(T)(void function(T*) test) { } And want to call it with a C function: foo!(SDL_Surface)(SDL_FreeSurface); but I get: Fe

Re: Call a function with a function pointer

2013-10-10 Thread Dicebot
On Thursday, 10 October 2013 at 14:40:09 UTC, Namespace wrote: Example? I do not use lambdas often. void foo(T)(void function(T*) test) { } extern(C) void bar(int*) { } void main() { foo( (int* a) => bar(a) ); } I don't know to what extent IFTI can work here though.

Re: Call a function with a function pointer

2013-10-10 Thread Namespace
On Thursday, 10 October 2013 at 14:26:37 UTC, Benjamin Thaut wrote: Am 10.10.2013 16:13, schrieb Namespace: I have this function: void foo(T)(void function(T*) test) { } And want to call it with a C function: foo!(SDL_Surface)(SDL_FreeSurface); but I get: Fehler1Err

Re: Call a function with a function pointer

2013-10-10 Thread Benjamin Thaut
Am 10.10.2013 16:13, schrieb Namespace: I have this function: void foo(T)(void function(T*) test) { } And want to call it with a C function: foo!(SDL_Surface)(SDL_FreeSurface); but I get: Fehler1Error: foo (void function(SDL_Surface*) test) is not callable using argu

Re: Call a function with a function pointer

2013-10-10 Thread Dicebot
On Thursday, 10 October 2013 at 14:13:47 UTC, Namespace wrote: I have this function: void foo(T)(void function(T*) test) { } And want to call it with a C function: foo!(SDL_Surface)(SDL_FreeSurface); but I get: Fehler 1 Error: foo (void function(SDL_Surface*) test) is not c