digitalmars.D - Are out-of-class-declaration method definitions allowed?
- AJ (15/15) Nov 12 2009 I can't imagine anyone that knows D doesn't also know C++, but the
- Ellery Newcomer (2/22) Nov 12 2009 not if you want to keep Doit virtual.
- BCS (3/20) Nov 12 2009 AFAIK That is not supported. You can do it by declaring an extern(C) fun...
- Steven Schveighoffer (14/30) Nov 13 2009 You can define MyClass in a .di file without implementations, and then
- bearophile (5/8) Nov 13 2009 In LDC there's a way to tell the compiler that a function that contains ...
I can't imagine anyone that knows D doesn't also know C++, but the opposite is hardly true, so here's some valid C++ that I'm wondering if there is an equivalent style allowed in D: class MyClass { public: void DoIt(); }; void MyClass::DoIt() { // do it } (Aside: D has no 'inline' keyword, correct? And, should I post questions like this post in the learn group? Even if the potential is likely that a language design discussion may result?)
Nov 12 2009
AJ wrote:I can't imagine anyone that knows D doesn't also know C++, but the opposite is hardly true, so here's some valid C++ that I'm wondering if there is an equivalent style allowed in D: class MyClass { public: void DoIt(); }; void MyClass::DoIt() { // do it } (Aside: D has no 'inline' keyword, correct? And, should I post questions like this post in the learn group? Even if the potential is likely that a language design discussion may result?)not if you want to keep Doit virtual.
Nov 12 2009
Hello aJ,I can't imagine anyone that knows D doesn't also know C++, but the opposite is hardly true, so here's some valid C++ that I'm wondering if there is an equivalent style allowed in D: class MyClass { public: void DoIt(); }; void MyClass::DoIt() { // do it } (Aside: D has no 'inline' keyword, correct? And, should I post questions like this post in the learn group? Even if the potential is likely that a language design discussion may result?)AFAIK That is not supported. You can do it by declaring an extern(C) function named with whatever that method's name mangles to ... but why?
Nov 12 2009
On Thu, 12 Nov 2009 23:19:21 -0500, AJ <aj nospam.net> wrote:I can't imagine anyone that knows D doesn't also know C++, but the opposite is hardly true, so here's some valid C++ that I'm wondering if there is an equivalent style allowed in D: class MyClass { public: void DoIt(); }; void MyClass::DoIt() { // do it }You can define MyClass in a .di file without implementations, and then rewrite it in the .d file with implementations. That's about as close as you can get.(Aside: D has no 'inline' keyword, correct? And, should I post questions like this post in the learn group? Even if the potential is likely that a language design discussion may result?)d.learn is probably the right place, though most people look at both. You'll get the occasional OCD post about how newbie questions really should be on d.learn, but it doesn't bother me :) inlining is done automatically by the compiler as long as it can see the entire function source and you pass the -inline command line switch to the compiler. The theory being -- the compiler probably knows better what things are good to inline. In practice, this sometimes isn't the case, but it's all we have to work with right now. -Steve
Nov 13 2009
Steven Schveighoffer:The theory being -- the compiler probably knows better what things are good to inline. In practice, this sometimes isn't the case, but it's all we have to work with right now.In LDC there's a way to tell the compiler that a function that contains asm is suitable for inlining. In LDC there's also a compilation flag that accepts a number, that's the inlining threshold, you can use it to inline less or inline more. I think 97% of the times the LDC compiler is able to do a good enough job of inlining. I remember only two times where LDC has not inlined something in need to be inlined. In this situations I've had to use an ugly string mixin, to create a kind of C macro, to inline those things by hand... Bye, bearophile
Nov 13 2009