digitalmars.D - (non-)extern(C) function parameter vs templates
- =?UTF-8?B?Ikx1w61z?= Marques" (20/20) Sep 17 2013 This works:
- =?UTF-8?B?Ikx1w61z?= Marques" (2/2) Sep 17 2013 Nevermind. Lack of sleep --;;
- John Colvin (16/36) Sep 17 2013 This works for me on dmd git master:
- =?UTF-8?B?Ikx1w61z?= Marques" (5/8) Sep 17 2013 Ah, OK! I said nevermind because the following works (on 2.063.2):
- =?UTF-8?B?Ikx1w61z?= Marques" (2/3) Sep 17 2013 I meant it didn't have to do with extern(C).
This works: extern(C) alias F = void function(); alias G = void function(); void foo(F f) {} void foo(G g) {} Indeed, the correct foo is called, depending on whether the passed function is extern(C) or not (although I must say that the syntax for declaring the alias F is not good, IMO; the extern(C) should come after the equal sign). Yet, the following does not work: void foo(T)(F f) {} void foo(G g) {} Error: function foo conflicts with template foo(T)(F f). or void foo(F f) {} void foo(T)(G g) {} Error: template foo(T)(E e) conflicts with function foo. It this not incoherent? If non-templated functions can overload on extern(C)/non-extern(C) function parameter, why can't templated functions?
Sep 17 2013
Nevermind. Lack of sleep --;; :-)
Sep 17 2013
On Tuesday, 17 September 2013 at 13:36:24 UTC, Luís Marques wrote:This works: extern(C) alias F = void function(); alias G = void function(); void foo(F f) {} void foo(G g) {} Indeed, the correct foo is called, depending on whether the passed function is extern(C) or not (although I must say that the syntax for declaring the alias F is not good, IMO; the extern(C) should come after the equal sign). Yet, the following does not work: void foo(T)(F f) {} void foo(G g) {} Error: function foo conflicts with template foo(T)(F f). or void foo(F f) {} void foo(T)(G g) {} Error: template foo(T)(E e) conflicts with function foo. It this not incoherent? If non-templated functions can overload on extern(C)/non-extern(C) function parameter, why can't templated functions?This works for me on dmd git master: extern(C) alias F = void function(); alias G = void function(); void foo(T)(T g) {} void foo(F f) {} extern(C) void a(){} void b(){} void main() { foo(&a); foo(&b); } It used to be that templates and normal functions couldn't overload each other, now they can. I'm not sure when the change was made, it might only be in git master.
Sep 17 2013
On Tuesday, 17 September 2013 at 13:50:20 UTC, John Colvin wrote:It used to be that templates and normal functions couldn't overload each other, now they can. I'm not sure when the change was made, it might only be in git master.Ah, OK! I said nevermind because the following works (on 2.063.2): void foo(T)(F f) { } void foo(T)(E e) { } So I guess it's more subtle than that. Thanks!
Sep 17 2013
On Tuesday, 17 September 2013 at 13:59:05 UTC, Luís Marques wrote:So I guess it's more subtle than that.I meant it didn't have to do with extern(C).
Sep 17 2013