digitalmars.D.learn - alias and extern(C) for callbacks
- Carl Sturtivant (13/13) Aug 22 2013 The D language page on interfacing to C
- Andrej Mitrovic (9/12) Aug 22 2013 Yes. If you want to make sure, you can use a trait:
- Carl Sturtivant (2/15) Aug 22 2013 Nice! Thank you.
- Jacob Carlborg (4/5) Aug 22 2013 Or Windows, Pascal or C++.
- Andrej Mitrovic (4/7) Aug 23 2013 I'd prefer if functionLinkage returned an enum, it's too easy to write
- Jacob Carlborg (4/7) Aug 23 2013 Yeah, that's a good point.
The D language page on interfacing to C http://dlang.org/interfaceToC.html says under 'Callbacks' that e.g. alias extern(C) int function(int, int) Callback; // D code is OK, so I am wondering if I can factor out the extern(C) from aliases as follows extern(C) { alias int function(int, int) Callback; // more aliases } Is Callback here a name for the same type as if it was defined by the following? alias extern(C) int function(int, int) Callback;
Aug 22 2013
On Thursday, 22 August 2013 at 23:55:44 UTC, Carl Sturtivant wrote:Is Callback here a name for the same type as if it was defined by the following? alias extern(C) int function(int, int) Callback;Yes. If you want to make sure, you can use a trait: import std.traits; extern(C) { void test1() { } } void test2() { } static assert(functionLinkage!test1 == "C"); static assert(functionLinkage!test2 != "C"); // D calling convention
Aug 22 2013
On Friday, 23 August 2013 at 00:00:13 UTC, Andrej Mitrovic wrote:On Thursday, 22 August 2013 at 23:55:44 UTC, Carl Sturtivant wrote:Nice! Thank you.Is Callback here a name for the same type as if it was defined by the following? alias extern(C) int function(int, int) Callback;Yes. If you want to make sure, you can use a trait: import std.traits; extern(C) { void test1() { } } void test2() { } static assert(functionLinkage!test1 == "C"); static assert(functionLinkage!test2 != "C"); // D calling convention
Aug 22 2013
On 2013-08-23 02:00, Andrej Mitrovic wrote:static assert(functionLinkage!test2 != "C"); // D calling conventionOr Windows, Pascal or C++. -- /Jacob Carlborg
Aug 22 2013
On 8/23/13, Jacob Carlborg <doob me.com> wrote:On 2013-08-23 02:00, Andrej Mitrovic wrote:I'd prefer if functionLinkage returned an enum, it's too easy to write "c" instead of "C" in some generic code and have a static if branch not taken.static assert(functionLinkage!test2 != "C"); // D calling conventionOr Windows, Pascal or C++.
Aug 23 2013
On 2013-08-23 13:10, Andrej Mitrovic wrote:I'd prefer if functionLinkage returned an enum, it's too easy to write "c" instead of "C" in some generic code and have a static if branch not taken.Yeah, that's a good point. -- /Jacob Carlborg
Aug 23 2013