Re: Zero-cost version-dependent function call at -O0.

2017-06-25 Thread Adam D. Ruppe via Digitalmars-d-learn
On Sunday, 25 June 2017 at 22:53:07 UTC, Johan Engelen wrote: I meant semantically no call. In the existing language, I think version (or static if) at the usage and definition points both is as good as you're going to get. unless you use a preprocessor lol But the good news about version

Re: Zero-cost version-dependent function call at -O0.

2017-06-25 Thread Johan Engelen via Digitalmars-d-learn
On Sunday, 25 June 2017 at 22:23:44 UTC, Moritz Maxeiner wrote: The solution obviously does *not* work if you change the premise of your question after the fact by artificially injecting instructions into all function bodies I meant semantically no call. I am asking for a little more

Re: Zero-cost version-dependent function call at -O0.

2017-06-25 Thread Moritz Maxeiner via Digitalmars-d-learn
On Sunday, 25 June 2017 at 21:55:22 UTC, Johan Engelen wrote: On Sunday, 25 June 2017 at 16:31:52 UTC, Moritz Maxeiner wrote: By requiring the compiler to inline the empty foo: This won't work. Yes, it does; comment out the call to `foo` and notice no change in the assembly in my link.

Re: Zero-cost version-dependent function call at -O0.

2017-06-25 Thread Johan Engelen via Digitalmars-d-learn
On Sunday, 25 June 2017 at 16:31:52 UTC, Moritz Maxeiner wrote: On Sunday, 25 June 2017 at 15:58:48 UTC, Johan Engelen wrote: [...] If version(X) is not defined, there should be no call and no extra code at -O0. [...] In C, you could do something like: ``` #if X void foo() {..} #else

Re: Zero-cost version-dependent function call at -O0.

2017-06-25 Thread Johan Engelen via Digitalmars-d-learn
On Sunday, 25 June 2017 at 16:29:20 UTC, Anonymouse wrote: Am I missing something, or can't you just version both the function and the function ćall? version(X) void foo() { /* ... */ } void main() { version(X) { foo(); } } I am hoping for something where "foo()" would

Re: Using templates with interfaces

2017-06-25 Thread via Digitalmars-d-learn
On Sunday, 25 June 2017 at 13:32:57 UTC, Andrew Chapman wrote: I think you've answered the question with "You cannot have unimplemented templates in interfaces". Thanks for the answer. I'll rethink the way I'm doing this. Cheers. In your case you can probably use something along the lines

Re: Using templates with interfaces

2017-06-25 Thread via Digitalmars-d-learn
On Sunday, 25 June 2017 at 13:32:57 UTC, Andrew Chapman wrote: I think you've answered the question with "You cannot have unimplemented templates in interfaces". Thanks for the answer. I'll rethink the way I'm doing this. Cheers. Yes, function templates in classes or interfaces are

Re: Zero-cost version-dependent function call at -O0.

2017-06-25 Thread Moritz Maxeiner via Digitalmars-d-learn
On Sunday, 25 June 2017 at 15:58:48 UTC, Johan Engelen wrote: [...] If version(X) is not defined, there should be no call and no extra code at -O0. [...] In C, you could do something like: ``` #if X void foo() {..} #else #define foo() #endif ``` How would you do this in D? By

Re: Zero-cost version-dependent function call at -O0.

2017-06-25 Thread Anonymouse via Digitalmars-d-learn
On Sunday, 25 June 2017 at 15:58:48 UTC, Johan Engelen wrote: How would you solve this problem: do an optional function call depending on some version(X). If version(X) is not defined, there should be no call and no extra code at -O0. ``` { ... foo(); // either compiles to a function

Zero-cost version-dependent function call at -O0.

2017-06-25 Thread Johan Engelen via Digitalmars-d-learn
How would you solve this problem: do an optional function call depending on some version(X). If version(X) is not defined, there should be no call and no extra code at -O0. ``` { ... foo(); // either compiles to a function call, or to _nothing_. ... } ``` In C, you could do something

Re: Interfacing with C - calling member function of D struct from C?

2017-06-25 Thread unleashy via Digitalmars-d-learn
On Sunday, 25 June 2017 at 02:09:53 UTC, Adam D. Ruppe wrote: On Sunday, 25 June 2017 at 02:05:35 UTC, unleashy wrote: How would I call `addToBar` from C code? You don't. Instead write it like: struct Foo { int bar; } extern(C) void addToBar(Foo* foo, int what) { foo.bar += what;

Re: Using templates with interfaces

2017-06-25 Thread Andrew Chapman via Digitalmars-d-learn
I think you've answered the question with "You cannot have unimplemented templates in interfaces". Thanks for the answer. I'll rethink the way I'm doing this. Cheers.

Re: Using templates with interfaces

2017-06-25 Thread Andrew Chapman via Digitalmars-d-learn
On Sunday, 25 June 2017 at 13:04:32 UTC, Nicholas Wilson wrote: On Sunday, 25 June 2017 at 11:39:27 UTC, Andrew Chapman wrote: Hi guys, I'm a little confused as to whether D supports interfaces with templates. I can compile OK, but linking reports an error like this: Error 42: Symbol

Re: Using templates with interfaces

2017-06-25 Thread Nicholas Wilson via Digitalmars-d-learn
On Sunday, 25 June 2017 at 11:39:27 UTC, Andrew Chapman wrote: Hi guys, I'm a little confused as to whether D supports interfaces with templates. I can compile OK, but linking reports an error like this: Error 42: Symbol Undefined

Accessing function frame from struct

2017-06-25 Thread Sebastien Alaiwan via Digitalmars-d-learn
Hi guys, here's my full code below. My problem is that last "auto Y = X" assignment, that the compiler won't accept: yo.globalFunction.DirectStruct.IndirectStruct.indirectMemberFunc cannot access frame of function yo.globalFunction I was expecting X to be accessible from here. Suprisingly,

Using templates with interfaces

2017-06-25 Thread Andrew Chapman via Digitalmars-d-learn
Hi guys, I'm a little confused as to whether D supports interfaces with templates. I can compile OK, but linking reports an error like this: Error 42: Symbol Undefined _D12relationaldb10interfaces21RÇëÜDBIÇêÿ35__T7loadRowTS6prefix÷6P¶ZÇêáMFAyaAS3std7variant18Çâ└8VÇåìNVki20ZÇëÅZÇûð