October 10, 2007 Re: DMD 1.022 and 2.005 releases | ||||
---|---|---|---|---|
| ||||
Posted in reply to 0ffh | 0ffh schrieb:
> BLS wrote:
>> Actually coding C++ code in D means : rewrite it and make it D-ish, instead of translate it.
>> This is , simply said shit; and I guess you folks know it.
>
> Nope, actually, I don't. If you're so in love with C++, why bother with D?
>
> Regards, Frank
NOOOOOoooo, clarification ;-), I don't like C++, BUT I need to translate some Cpp libs into D. And sometimes it is difficult to do this job 'cause D 1.x actually lacks some of C++ features. (but D 2 comes with struct inheritance., opImplicitCastX, DTL, ....)
Bjoern
beside, C++ is No 2 on my personal programming language SL
|
October 10, 2007 Re: DMD 1.022 and 2.005 releases | ||||
---|---|---|---|---|
| ||||
Posted in reply to BLS | BLS wrote: > 0ffh schrieb: >> If you're so in love with C++, why bother with D? > NOOOOOoooo, clarification ;-), I don't like C++, BUT I need to translate > some Cpp libs into D. And sometimes it is difficult to do this job [...] I suppose life just isn't fair. =) > beside, C++ is No 2 on my personal programming language SL What is an SL? Earlier, BLS wrote: > &references ... The Rationales do not say a anything about it The D "compared to C" just says ... We don't have it. Yup, and good riddance I say! IMHO even the out/ref keyword is a mistake! (It's also the only mistake of it's kind in Pascal, btw.) > Struct inheritance Why we need an *alias here instead of just writing structA : structB; Maybe you have a point here. I suppose mixins can't be used, as there would probably be a problem overriding. > C++ op overloading; D is not competitive. Hmmmm.... I can't recall any major issues here. Regards, Frank |
October 10, 2007 Re: DMD 1.022 and 2.005 releases | ||||
---|---|---|---|---|
| ||||
Posted in reply to 0ffh | 0ffh schrieb: > BLS wrote: >> 0ffh schrieb: >>> If you're so in love with C++, why bother with D? >> NOOOOOoooo, clarification ;-), I don't like C++, BUT I need to translate >> some Cpp libs into D. And sometimes it is difficult to do this job [...] > > I suppose life just isn't fair. =) > >> beside, C++ is No 2 on my personal programming language SL > > What is an SL? > I am pretty sure Gerhard Schroeder still has a top ten placement on George W. Bush's S-List, HTH :) > Earlier, BLS wrote: >> &references ... The Rationales do not say a anything about it The D "compared to C" just says ... We don't have it. > > Yup, and good riddance I say! > IMHO even the out/ref keyword is a mistake! > (It's also the only mistake of it's kind in Pascal, btw.) > I do not agree, but this is not the point. The problem is that C++ folks seems to love this feature, and I have to translate it into D (somehow). >> Struct inheritance Why we need an *alias here instead of just writing structA : structB; > > Maybe you have a point here. I suppose mixins can't be used, as there > would probably be a problem overriding. > >> C++ op overloading; D is not competitive. > > Hmmmm.... I can't recall any major issues here. > For example : // Allready translated C++ stuff class CFont { public: HFONT m_hFont; this(HFONT hFont = null) { m_hFont = hFont; } ~this() { if(m_hFont !is null && !DeleteObject(m_hFont)) m_hFont = null; } // TODO How to translate this C++ construct into D operator HFONT() {return m_hFont;} // That's the problem. But as allready said/ D 2 opImplicitCast may solve the problem. > Regards, Frank Thanks Bjoern |
October 10, 2007 Re: DMD 1.022 and 2.005 releases | ||||
---|---|---|---|---|
| ||||
Posted in reply to BLS | BLS wrote:
> 0ffh schrieb:
>> Earlier, BLS wrote:
>>> &references ... The Rationales do not say a anything about it The D "compared to C" just says ... We don't have it.
>> Yup, and good riddance I say!
>> IMHO even the out/ref keyword is a mistake!
>> (It's also the only mistake of it's kind in Pascal, btw.)
> I do not agree, but this is not the point. The problem is that C++ folks seems to love this feature, and I have to translate it into D (somehow).
With the help of explicit pointers and dereferencing, I can see no trouble
except you'll need a lot of stars... :)
Regards, Frank
ps. btw. plain C doesn't have &refs either
|
October 10, 2007 Re: DMD 1.022 and 2.005 releases | ||||
---|---|---|---|---|
| ||||
Posted in reply to 0ffh | 0ffh schrieb: > With the help of explicit pointers and dereferencing, I can see no trouble > except you'll need a lot of stars... :) > > Regards, Frank > > ps. btw. plain C doesn't have &refs either Would be nice if you are willing to offer an example. It could also be used as example on : http://www.prowiki.org/wiki4d/wiki.cgi?PortingFromCxx thanks in advance, Bjoern |
October 10, 2007 Re: DMD 1.022 and 2.005 releases | ||||
---|---|---|---|---|
| ||||
Posted in reply to BLS | BLS wrote:
> 0ffh schrieb:
>
>> With the help of explicit pointers and dereferencing, I can see no trouble
>> except you'll need a lot of stars... :)
>>
>> Regards, Frank
>>
>> ps. btw. plain C doesn't have &refs either
>
> Would be nice if you are willing to offer an example.
> It could also be used as example on :
> http://www.prowiki.org/wiki4d/wiki.cgi?PortingFromCxx
> thanks in advance, Bjoern
He just means have the function return Foo* instead of Foo&. And then use (*foo) everwhere instead of plain foo on calling side. That's pretty much the only reasonable solution I can see.
--bb
|
October 10, 2007 Re: DMD 1.022 and 2.005 releases | ||||
---|---|---|---|---|
| ||||
Posted in reply to Bill Baxter | Bill Baxter schrieb:
> BLS wrote:
>> 0ffh schrieb:
>>
>>> With the help of explicit pointers and dereferencing, I can see no trouble
>>> except you'll need a lot of stars... :)
>>>
>>> Regards, Frank
>>>
>>> ps. btw. plain C doesn't have &refs either
>>
>> Would be nice if you are willing to offer an example.
>> It could also be used as example on :
>> http://www.prowiki.org/wiki4d/wiki.cgi?PortingFromCxx
>> thanks in advance, Bjoern
>
> He just means have the function return Foo* instead of Foo&. And then use (*foo) everwhere instead of plain foo on calling side. That's pretty much the only reasonable solution I can see.
>
> --bb
Thanks for clarification Bill. Wonder why Frank wrote : "except you'll need a lot of * " ?
Bjoern
|
October 10, 2007 Re: DMD 1.022 and 2.005 releases | ||||
---|---|---|---|---|
| ||||
Posted in reply to BLS | BLS wrote:
> Bill Baxter schrieb:
>> BLS wrote:
>>> 0ffh schrieb:
>>>
>>>> With the help of explicit pointers and dereferencing, I can see no trouble
>>>> except you'll need a lot of stars... :)
>>>>
>>>> Regards, Frank
>>>>
>>>> ps. btw. plain C doesn't have &refs either
>>>
>>> Would be nice if you are willing to offer an example.
>>> It could also be used as example on :
>>> http://www.prowiki.org/wiki4d/wiki.cgi?PortingFromCxx
>>> thanks in advance, Bjoern
>>
>> He just means have the function return Foo* instead of Foo&. And then use (*foo) everwhere instead of plain foo on calling side. That's pretty much the only reasonable solution I can see.
>>
>> --bb
> Thanks for clarification Bill. Wonder why Frank wrote : "except you'll need a lot of * " ?
> Bjoern
>
I assumed he meant something like:
-- C++ --
void foo(int &i)
{
..lots of uses of 'i' eg "i = 5"..
}
-- D --
void foo(int *i)
{
..lots of uses of '*i' eg "*i = 5"..
}
each usage of a converted ref parameter will require a *.
The other problem here however is the call site:
-- C++ --
int i;
foo(i);
-- D --
int i;
foo(&i);
Regan
|
October 10, 2007 Re: DMD 1.022 and 2.005 releases | ||||
---|---|---|---|---|
| ||||
Posted in reply to BLS | BLS wrote:
> Would be nice if you are willing to offer an example.
> It could also be used as example on :
> http://www.prowiki.org/wiki4d/wiki.cgi?PortingFromCxx
> thanks in advance, Bjoern
Okay, I am more a C type of person not C++, so I hope
I do not write anything wrong now... :)
I have a C++ function getting an int &a:
---<snip>---
void addTo(int &a,int b)
{
a+=b;
}
void main()
{
int a=5;
addTo(a,3);
printf("a=%i\n",a); // prints "a=8\n"
}
---<snap>---
IIRC this is really just syntactic sugar for passing
a pointer that is automatically dereferenced.
In C I replace the &a with an *a and dereference:
---<snip>---
void addTo(int *a,int b) // &a -> *a
{
(*a)+=b; // a -> (*a)
}
void main()
{
int a=5;
addTo(&a,3); // a -> &a
printf("a=%i\n",a); // prints "a=8\n"
}
---<snap>---
This has the added advantage, that at the point where the
function is called, I can see that a pointer is passed,
while in C++ I can't. That's why C++ coders so often write
(const T &ref) to avoid accidential side effects which
would be hard to find just looking at the function call.
This might work in D, although I have never tried it:
---<snip>---
void addTo(ref int a,int b)
{
a+=b;
}
void main()
{
int a=5;
addTo(a,3);
printf("a=%i\n",a); // prints "a=8\n"
}
---<snap>---
Regards, Frank
|
October 10, 2007 Re: DMD 1.022 and 2.005 releases | ||||
---|---|---|---|---|
| ||||
Posted in reply to Regan Heath | Regan Heath schrieb: > BLS wrote: >> Bill Baxter schrieb: >>> BLS wrote: >>>> 0ffh schrieb: >>>> >>>>> With the help of explicit pointers and dereferencing, I can see no trouble >>>>> except you'll need a lot of stars... :) >>>>> >>>>> Regards, Frank >>>>> >>>>> ps. btw. plain C doesn't have &refs either >>>> >>>> Would be nice if you are willing to offer an example. >>>> It could also be used as example on : >>>> http://www.prowiki.org/wiki4d/wiki.cgi?PortingFromCxx >>>> thanks in advance, Bjoern >>> >>> He just means have the function return Foo* instead of Foo&. And then use (*foo) everwhere instead of plain foo on calling side. That's pretty much the only reasonable solution I can see. >>> >>> --bb >> Thanks for clarification Bill. Wonder why Frank wrote : "except you'll need a lot of * " ? >> Bjoern >> > > I assumed he meant something like: > > -- C++ -- > void foo(int &i) > { > ..lots of uses of 'i' eg "i = 5".. > } > > -- D -- > void foo(int *i) > { > ..lots of uses of '*i' eg "*i = 5".. > } > I think : void foo(ref int i){} will do the Job in D ( But function parameters are not part of the problem ) Thanks, Bjoern > each usage of a converted ref parameter will require a *. > > The other problem here however is the call site: > > -- C++ -- > int i; > foo(i); > > -- D -- > int i; > foo(&i); > > Regan |
Copyright © 1999-2021 by the D Language Foundation