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
Error: foo (void function(SDL_Surface*) test) is not callable using argument types (extern (C) void function(SDL_Surface*) nothrow) What would be the smartest solution? If you can change the signature of foo just add a extern(c) to the function pointer declaration. Otherwise just wrap the

Re: Call a function with a function pointer

2013-10-10 Thread Benjamin Thaut
argument types (extern (C) void function(SDL_Surface*) nothrow) What would be the smartest solution? If you can change the signature of foo just add a extern(c) to the function pointer declaration. Otherwise just wrap the SDL_FreeSurface call into a delegate on the caller side. -- Kind Regards

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

Call a function with a function pointer

2013-10-10 Thread 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: Fehler 1 Error: foo (void function(SDL_Surface*) test) is not callable using argument types (extern (C) void function(SDL_Surf

Re: How to define struct with function pointer member ?

2013-07-28 Thread Gabi
On Sunday, 28 July 2013 at 22:13:13 UTC, H. S. Teoh wrote: On Mon, Jul 29, 2013 at 12:04:55AM +0200, Gabi wrote: I tried: struct X { .. function double(Individual) someFun; [...] The correct syntax is: double function(Individual) someFun; T Yes thanks. Beginner's mistake :)

Re: How to define struct with function pointer member ?

2013-07-28 Thread Gabi
On Sunday, 28 July 2013 at 22:04:57 UTC, Gabi wrote: I tried: struct X { .. function double(Individual) someFun; .. } But get: Error: Declaration expected, not 'function' Thanks, Gabi Sorry I found the answer. Should have declared double function(...) someFun;

Re: How to define struct with function pointer member ?

2013-07-28 Thread H. S. Teoh
On Mon, Jul 29, 2013 at 12:04:55AM +0200, Gabi wrote: > I tried: > > struct X > { > .. > function double(Individual) someFun; [...] The correct syntax is: double function(Individual) someFun; T -- Music critic: "That's an imitation fugue!"

How to define struct with function pointer member ?

2013-07-28 Thread Gabi
I tried: struct X { .. function double(Individual) someFun; .. } But get: Error: Declaration expected, not 'function' Thanks, Gabi

Re: Function pointer variable not recognized as function by is-operator

2012-10-07 Thread Jonathan M Davis
On Sunday, October 07, 2012 10:42:49 Timon Gehr wrote: > On 10/07/2012 10:35 AM, Jonathan M Davis wrote: > > On Sunday, October 07, 2012 10:25:41 Tommi wrote: > >> The following compiles, which I'm pretty sure must be a bug, > >> right? Just checking to be sure I won't be polluting the bug > >> tra

Re: Function pointer variable not recognized as function by is-operator

2012-10-07 Thread Timon Gehr
On 10/07/2012 10:35 AM, Jonathan M Davis wrote: On Sunday, October 07, 2012 10:25:41 Tommi wrote: The following compiles, which I'm pretty sure must be a bug, right? Just checking to be sure I won't be polluting the bug tracker. void main() { auto f = (int i) {}; static assert (!is(

Re: Function pointer variable not recognized as function by is-operator

2012-10-07 Thread Jonathan M Davis
On Sunday, October 07, 2012 10:25:41 Tommi wrote: > The following compiles, which I'm pretty sure must be a bug, > right? Just checking to be sure I won't be polluting the bug > tracker. > > void main() > { > auto f = (int i) {}; > static assert (!is(f == function)); // should fail >

Function pointer variable not recognized as function by is-operator

2012-10-07 Thread Tommi
The following compiles, which I'm pretty sure must be a bug, right? Just checking to be sure I won't be polluting the bug tracker. void main() { auto f = (int i) {}; static assert (!is(f == function)); // should fail static assert (!is(f == delegate)); }

Re: function pointer and default argument

2012-08-22 Thread Ali Çehreli
//dmd: ok > fn(1); // dmd: not ok > } The type of the function pointer does not include the values of the default parameters. typeof lies. pragma(msg, typeof(fn)); > void function(int i, double j = 1) Opened: http://d.puremagic.com/issues/show_bug.cgi?id=8579 Ali

Re: function pointer and default argument

2012-08-22 Thread Jonathan M Davis
On Wednesday, August 22, 2012 11:51:45 Ellery Newcomer wrote: > hey. > > is this valid code? > > void func1(int i, double j = 1.0) { > } > > void main() { > auto fn = &func1; > func1(1); //dmd: ok > fn(1); // dmd: not ok > } Default arguments are not part of the type. This behavior is very much

Re: function pointer and default argument

2012-08-22 Thread Ellery Newcomer
On 08/22/2012 12:03 PM, Ali Çehreli wrote: On 08/22/2012 11:51 AM, Ellery Newcomer wrote: > hey. > > is this valid code? > > void func1(int i, double j = 1.0) { > } > > void main() { > auto fn = &func1; > func1(1); //dmd: ok > fn(1); // dmd:

Re: function pointer and default argument

2012-08-22 Thread Ali Çehreli
On 08/22/2012 11:51 AM, Ellery Newcomer wrote: > hey. > > is this valid code? > > void func1(int i, double j = 1.0) { > } > > void main() { > auto fn = &func1; > func1(1); //dmd: ok > fn(1); // dmd: not ok > } The type of the function pointer doe

function pointer and default argument

2012-08-22 Thread Ellery Newcomer
hey. is this valid code? void func1(int i, double j = 1.0) { } void main() { auto fn = &func1; func1(1); //dmd: ok fn(1); // dmd: not ok }

Re: Portable way to obtain member function pointer (and invoke it)?

2012-07-08 Thread Benjamin Thaut
time: auto func = &object.func; This will create a delegate with the this pointer and the function pointer. If you want to build it manually you can do that also: alias void delegate() func_t; func_t func; func.funcptr = GetFunctionPointer(); func.ptr = object; Kind Regards Benjamin Thaut

Re: Portable way to obtain member function pointer (and invoke it)?

2012-07-08 Thread Timon Gehr
On 07/08/2012 09:57 PM, Alex Rønne Petersen wrote: Hi, Is there a portable way to obtain a pointer to a member function and invoke it with the this reference? I seem to recall some discussion about this on the NG in the past, but can't find the thread now. auto mptr = function(Base o,Args arg

Portable way to obtain member function pointer (and invoke it)?

2012-07-08 Thread Alex Rønne Petersen
Hi, Is there a portable way to obtain a pointer to a member function and invoke it with the this reference? I seem to recall some discussion about this on the NG in the past, but can't find the thread now. -- Alex Rønne Petersen a...@lycus.org http://lycus.org

Re: function pointer when a function is overloaded.

2012-07-01 Thread deadalnix
Le 01/07/2012 01:59, dnewbie a écrit : import std.stdio; alias void function(int) fooInt; alias void function(long) fooLong; int main(string[] args) { fooInt f1 = &foo; fooLong f2 = &foo; f1(1L); f2(1L); return 0; } void foo(int i) { writeln("foo(int i)"); } void foo(long i) { writeln("foo(lo

Re: function pointer when a function is overloaded.

2012-06-30 Thread dnewbie
import std.stdio; alias void function(int) fooInt; alias void function(long) fooLong; int main(string[] args) { fooInt f1 = &foo; fooLong f2 = &foo; f1(1L); f2(1L); return 0; } void foo(int i) { writeln("foo(int i)"); } void foo(long i) { writeln("foo(long i)"); }

function pointer when a function is overloaded.

2012-06-30 Thread deadalnix
Simple question. How to I get a function pointer to one of the foo functions in this case : void foo(int i); void foo(long i);

Re: function pointer from DLL

2012-01-13 Thread Andrej Mitrovic
Your problem was that you didn't cast the function pointer to an extern(C) function. Unfortunately you can't do this inline (I can't tell if this will be fixed or not), so you have to use an alias as a workaround: alias extern (C) int function(void*,int,int,int) SciFnDirect; fn = c

Re: function pointer from DLL

2012-01-13 Thread DNewbie
On Sat, Jan 14, 2012, at 06:04 AM, Andrej Mitrovic wrote: > On 1/14/12, Andrej Mitrovic wrote: > > You can clone this: g...@github.com:AndrejMitrovic/DSciteWin.git > > > > Then just run build.bat. > > > > Sorry, I've assumed you run git, the http link is: > https://github.com/AndrejMitrovic/DSci

Re: function pointer from DLL

2012-01-13 Thread Andrej Mitrovic
On 1/14/12, Andrej Mitrovic wrote: > You can clone this: g...@github.com:AndrejMitrovic/DSciteWin.git > > Then just run build.bat. > Sorry, I've assumed you run git, the http link is: https://github.com/AndrejMitrovic/DSciteWin

Re: function pointer from DLL

2012-01-13 Thread Andrej Mitrovic
You can clone this: g...@github.com:AndrejMitrovic/DSciteWin.git Then just run build.bat.

function pointer from DLL

2012-01-13 Thread DNewbie
I've been trying to translate the following from http://www.scintilla.org/Steps.html int (*fn)(void*,int,int,int); void * ptr; int canundo; fn = (int (__cdecl *)(void *,int,int,int))SendMessage( hwndScintilla,SCI_GETDIRECTFUNCTION,0,0); ptr = (void *)SendMessage(hwndScintilla,SCI_GETDIRE

Re: How to use a member function (delegate) as a function pointer

2010-10-31 Thread Daniel Murphy
"Peter Federighi" wrote in message news:ial8hq$213...@digitalmars.com... > Is there a way to do it without removing handler() from the class? When I > try > compiling, I get: Error: cannot implicitly convert expression > (&this.handler) > of type void delegate(int signal) to void C function(in

Re: How to use a member function (delegate) as a function pointer

2010-10-31 Thread Denis Koroskin
he class? When I try compiling, I get: Error: cannot implicitly convert expression (&this.handler) of type void delegate(int signal) to void C function(int). Thank you, - Peter No, unfortunately not. A delegate is a function pointer PLUS 'this'. The C API you are using allows pro

How to use a member function (delegate) as a function pointer

2010-10-31 Thread Peter Federighi
Hello. I'm new to D. It's been a long time since I've coded anything with classes. Please excuse my ignorance. Here's a very simplified version of what I'm trying to do: import std.c.linux.linux; import std.stdio; class FOO { this() { sa.sa_handler = &handler; si

Re: Translation of C function pointer.

2010-09-17 Thread Jonathan M Davis
On Friday, September 17, 2010 17:07:15 Simen kjaeraas wrote: > Jonathan M Davis wrote: > >> I've always been confused by C in this regard. It seems to logical to me > >> that T[3] works the same whether T is U[4] or U. > > > > You're going to have to elaborate on that. I'm not quite sure what you

Re: Translation of C function pointer.

2010-09-17 Thread Simen kjaeraas
Jonathan M Davis wrote: I've always been confused by C in this regard. It seems to logical to me that T[3] works the same whether T is U[4] or U. You're going to have to elaborate on that. I'm not quite sure what you're talking about. And the syntax int[4][3] isn't legal C anyway. It just d

Re: Translation of C function pointer.

2010-09-17 Thread Jesse Phillips
Jonathan M Davis Wrote: > On Friday, September 17, 2010 10:43:12 Ali Çehreli wrote: > > > > int[4] is an array of 4 ints; like Simen, let's call it U. > > Now U[3] is an array of 3 Us; i.e. 3 int[4]s > > > > I read that from left to right, not inside out. > > No, no. You read it outwards from t

Re: Translation of C function pointer.

2010-09-17 Thread Jonathan M Davis
On Friday, September 17, 2010 10:43:12 Ali Çehreli wrote: > Jonathan M Davis wrote: > > On Thursday 16 September 2010 23:50:16 Kagamin wrote: > >> BCS Wrote: > >>> The trick is that function pointers are best read from the inside out. > >> > >> All C declarations are read from inside out, pos

Re: Translation of C function pointer.

2010-09-17 Thread Jonathan M Davis
On Friday, September 17, 2010 05:00:55 Simen kjaeraas wrote: > On Fri, 17 Sep 2010 10:12:34 +0200, Jonathan M Davis > > wrote: > > On Thursday 16 September 2010 23:50:16 Kagamin wrote: > >> BCS Wrote: > >> > The trick is that function pointers are best read from the inside out. > >> > >> All C d

Re: Translation of C function pointer.

2010-09-17 Thread Ali Çehreli
Jonathan M Davis wrote: > On Thursday 16 September 2010 23:50:16 Kagamin wrote: >> BCS Wrote: >>> The trick is that function pointers are best read from the inside out. >> All C declarations are read from inside out, postfixes take precedence, >> that's why you have to use braces to give pointer h

Re: Translation of C function pointer.

2010-09-17 Thread Simen kjaeraas
On Fri, 17 Sep 2010 10:12:34 +0200, Jonathan M Davis wrote: On Thursday 16 September 2010 23:50:16 Kagamin wrote: BCS Wrote: > The trick is that function pointers are best read from the inside out. All C declarations are read from inside out, postfixes take precedence, that's why you have t

Re: Translation of C function pointer.

2010-09-17 Thread Jonathan M Davis
On Thursday 16 September 2010 23:50:16 Kagamin wrote: > BCS Wrote: > > The trick is that function pointers are best read from the inside out. > > All C declarations are read from inside out, postfixes take precedence, > that's why you have to use braces to give pointer higher precedence. One > of

Re: Translation of C function pointer.

2010-09-16 Thread Kagamin
BCS Wrote: > The trick is that function pointers are best read from the inside out. > -- All C declarations are read from inside out, postfixes take precedence, that's why you have to use braces to give pointer higher precedence. One of the earlier books by Stroustroup gives a nice monster of a

Re: Translation of C function pointer.

2010-09-16 Thread Stewart Gordon
outermost level, you end up with (note (void) becomes ()) void function() (*xDlSym)(sqlite3_vfs*,void*, const char *zSymbol); instead of Name, you've got this funny thing. You're left with a function pointer declaration where void function() is the ReturnType, so transformi

Re: Translation of C function pointer.

2010-09-16 Thread BCS
Hello Steven, On Thu, 16 Sep 2010 10:06:24 -0400, BCS wrote: Hello Steven, // note you can't use void as a parameter type in D void (*(*xDlSym)(sqlite3_vfs*,void*, const char *zSymbol))(/*void*/); pragma(msg, typeof(xDlSym).stringof); outputs: void function() function(sqlite3_vfs*, void*, c

Re: Translation of C function pointer.

2010-09-16 Thread Stewart Gordon
) D, now with C type un-garbleing! Perhaps the only excuse for keeping C-style function pointer declarations in D. But since we have htod, we could just as well use it and leave D free to get rid of this fossil that leads to a syntactic ambiguity. Except that I've just found htod

Re: Translation of C function pointer.

2010-09-16 Thread Steven Schveighoffer
On Thu, 16 Sep 2010 10:06:24 -0400, BCS wrote: Hello Steven, // note you can't use void as a parameter type in D void (*(*xDlSym)(sqlite3_vfs*,void*, const char *zSymbol))(/*void*/); pragma(msg, typeof(xDlSym).stringof); outputs: void function() function(sqlite3_vfs*, void*, const const(char

Re: Translation of C function pointer.

2010-09-16 Thread BCS
Hello Steven, // note you can't use void as a parameter type in D void (*(*xDlSym)(sqlite3_vfs*,void*, const char *zSymbol))(/*void*/); pragma(msg, typeof(xDlSym).stringof); outputs: void function() function(sqlite3_vfs*, void*, const const(char*) zSymbol) D, now with C type un-garbleing! --

Re: Translation of C function pointer.

2010-09-15 Thread Yao G.
DlSym).stringof); outputs: void function() function(sqlite3_vfs*, void*, const const(char*) zSymbol) so I think it's a function pointer that takes those parameters and returns a function pointer that takes no parameters and returns nothing. -Steve Thanks Steve! -- Yao G.

Re: Translation of C function pointer.

2010-09-15 Thread Steven Schveighoffer
On Wed, 15 Sep 2010 17:05:24 -0400, Yao G. wrote: Hello gentlemen: I'm trying to translate the newest SQLite C header to D, and I stumbled unto this gem: void (*(*xDlSym)(sqlite3_vfs*,void*, const char *zSymbol))(void); What's that? A function pointer that takes anothe

Re: Translation of C function pointer.

2010-09-15 Thread Steven Schveighoffer
(void); What's that? A function pointer that takes another function pointer as its name? I'm stuck at this and I don't know how to convert it to a D function pointer. Certainly, the inner pointer is easy: void (* function(sqlite3_vfs*,void*, const(char) *zSymbol) xDlSym)();

Translation of C function pointer.

2010-09-15 Thread Yao G.
Hello gentlemen: I'm trying to translate the newest SQLite C header to D, and I stumbled unto this gem: void (*(*xDlSym)(sqlite3_vfs*,void*, const char *zSymbol))(void); What's that? A function pointer that takes another function pointer as its name? I'm stuck at this and I

Re: Type literal of pure function pointer

2010-07-25 Thread bearophile
Simen kjaeraas: > Add it to Bugzilla. Another case is that this works: > > alias pure int function( int ) FN; > pure foo4( FN fn, int x ) { > return fn( x ); > } > > It seems the problem is that type specification in function signatures > does not support the full range of type signature in

Re: Type literal of pure function pointer

2010-07-25 Thread Simen kjaeraas
On Sun, 25 Jul 2010 01:10:54 +0200, bearophile wrote: In the following D2 the D type system is strong enough to allow foo1() to be pure because sqr() is a pointer to a pure function. In foo2() I have tried to do the same thing avoiding templates, and it works. In foo3() I have tried to w

Type literal of pure function pointer

2010-07-24 Thread bearophile
In the following D2 the D type system is strong enough to allow foo1() to be pure because sqr() is a pointer to a pure function. In foo2() I have tried to do the same thing avoiding templates, and it works. In foo3() I have tried to write the type literal, but I was not able to: pure int sqr(i

<    1   2