digitalmars.D - Are interfaces supported in Better C mode?
- Dibyendu Majumdar (9/9) Nov 14 2020 Reading the docs on Better C mode I got the impression that it
- Dibyendu Majumdar (10/13) Nov 14 2020 I guess it needs to be class?
- Dibyendu Majumdar (18/25) Nov 14 2020 Well this compiles but doesn't link.
- kinke (16/17) Nov 14 2020 This works with LDC:
- Dibyendu Majumdar (7/24) Nov 14 2020 Hi,
- Dibyendu Majumdar (2/10) Nov 14 2020 I thought new isn't supported in better C mode ?
- Paul Backus (4/16) Nov 14 2020 `scope` causes the class instance to be allocated on the stack.
- Dibyendu Majumdar (2/6) Nov 14 2020 Okay thank you - I didn't know that.
- Dibyendu Majumdar (3/6) Nov 21 2020 https://issues.dlang.org/show_bug.cgi?id=21412
- Dibyendu Majumdar (19/26) Nov 21 2020 Looks like this works with DMD and LDC:
Reading the docs on Better C mode I got the impression that it should be possible to implement an interface in a struct. Is this not the case? I tried extern (C++) too, but I get an error. extern (C++) interface A { void sayHello(); } extern (C++) struct B : A { }
Nov 14 2020
On Saturday, 14 November 2020 at 21:09:59 UTC, Dibyendu Majumdar wrote:Reading the docs on Better C mode I got the impression that it should be possible to implement an interface in a struct. Is this not the case?I guess it needs to be class? extern (C++) interface A { void sayHello(); } extern (C++) class B : A { void sayHello() {} } Above seems to compile.
Nov 14 2020
On Saturday, 14 November 2020 at 21:40:31 UTC, Dibyendu Majumdar wrote:On Saturday, 14 November 2020 at 21:09:59 UTC, Dibyendu Majumdar wrote:Well this compiles but doesn't link. import core.stdc.stdio : printf; extern (C++) interface A { void sayHello(); } extern (C++) class B : A { void sayHello() { printf("hello\n"); } } extern (C) void main() { B b; b.sayHello(); } /opt/rh/devtoolset-9/root/usr/libexec/gcc/x86_64-redhat-linux/9/ld: interfaces.o:(.data._D10interfaces1A11__InterfaceZ+0x0): undefined reference to `_D14TypeInfo_Class6__vtblZ' /opt/rh/devtoolset-9/root/usr/libexec/gcc/x86_64-redhat-linux/9/ld: interfaces.o:(.data._D10interfaces1B6__initZ+0x8): undefined reference to `_D10interfaces1B7__ClassZ'Reading the docs on Better C mode I got the impression that it should be possible to implement an interface in a struct. Is this not the case?I guess it needs to be class?
Nov 14 2020
On Saturday, 14 November 2020 at 21:46:38 UTC, Dibyendu Majumdar wrote:Well this compiles but doesn't link.This works with LDC: import core.stdc.stdio : printf; extern (C++) interface A { void sayHello(); } extern (C++) class B : A { void sayHello() { printf("hello\n"); } } extern (C) void main() { scope b = new B; b.sayHello(); }
Nov 14 2020
On Sunday, 15 November 2020 at 01:00:27 UTC, kinke wrote:On Saturday, 14 November 2020 at 21:46:38 UTC, Dibyendu Majumdar wrote:Hi, I downloaded ldc2 1.24 and tried this out. It compiled and linked okay - but crashes with segmentation fault on the line that invokes the sayHello() method. I am on RHEL 7.9. RegardsWell this compiles but doesn't link.This works with LDC: import core.stdc.stdio : printf; extern (C++) interface A { void sayHello(); } extern (C++) class B : A { void sayHello() { printf("hello\n"); } } extern (C) void main() { scope b = new B; b.sayHello(); }
Nov 14 2020
On Sunday, 15 November 2020 at 01:00:27 UTC, kinke wrote:On Saturday, 14 November 2020 at 21:46:38 UTC, Dibyendu Majumdar wrote:I thought new isn't supported in better C mode ?Well this compiles but doesn't link.This works with LDC: extern (C) void main() { scope b = new B; b.sayHello(); }
Nov 14 2020
On Sunday, 15 November 2020 at 01:30:24 UTC, Dibyendu Majumdar wrote:On Sunday, 15 November 2020 at 01:00:27 UTC, kinke wrote:`scope` causes the class instance to be allocated on the stack. Source: https://dlang.org/spec/expression.html#new_expressionsOn Saturday, 14 November 2020 at 21:46:38 UTC, Dibyendu Majumdar wrote:I thought new isn't supported in better C mode ?Well this compiles but doesn't link.This works with LDC: extern (C) void main() { scope b = new B; b.sayHello(); }
Nov 14 2020
On Sunday, 15 November 2020 at 01:43:00 UTC, Paul Backus wrote:On Sunday, 15 November 2020 at 01:30:24 UTC, Dibyendu MajumdarOkay thank you - I didn't know that.I thought new isn't supported in better C mode ?`scope` causes the class instance to be allocated on the stack. Source: https://dlang.org/spec/expression.html#new_expressions
Nov 14 2020
On Saturday, 14 November 2020 at 21:09:59 UTC, Dibyendu Majumdar wrote:Reading the docs on Better C mode I got the impression that it should be possible to implement an interface in a struct. Is this not the case?https://issues.dlang.org/show_bug.cgi?id=21412
Nov 21 2020
On Saturday, 21 November 2020 at 23:48:06 UTC, Dibyendu Majumdar wrote:On Saturday, 14 November 2020 at 21:09:59 UTC, Dibyendu Majumdar wrote:Looks like this works with DMD and LDC: import core.stdc.stdio : printf; extern (C++) abstract class A { void sayHello(); } extern (C++) class B : A { override void sayHello() { printf("hello\n"); } } extern (C) void main() { scope b = new B; b.sayHello(); } So - replacing 'interface' with 'abstract class' solved it. Also need to use 'new' to allocate. Compiler doesn't complain about the null value.Reading the docs on Better C mode I got the impression that it should be possible to implement an interface in a struct. Is this not the case?https://issues.dlang.org/show_bug.cgi?id=21412
Nov 21 2020