October 10, 2007
BLS wrote:
> I think :
> void foo(ref int i){}
> will do the Job in D
> ( But function parameters are not part of the problem )

I know that, I was just guessing what 0ffh (aka Frank) was referring to.

Regan
October 10, 2007
BLS wrote:
> 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

Except if you try to call  foo(42).
 -- ERROR 42 is not an lvalue

(Which is another reason why they're often made const in C++ -- you can pass a literal or temporary to a const T&, but not to a T&.

--bb
October 10, 2007
0ffh schrieb:
> 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
Thanks Frank.
Yes the (ref int a) stuff works fine.
But function parameters are not part of the problem

The problem is ;
//C++
int value = 100;
int & rIntRef = value;

Bjoern
October 10, 2007
Regan Heath schrieb:
> BLS wrote:
>> I think :
>> void foo(ref int i){}
>> will do the Job in D
>> ( But function parameters are not part of the problem )
> 
> I know that, I was just guessing what 0ffh (aka Frank) was referring to.
Okay Sorry !
> 
> Regan

The problem is ;
//C++
int value = 100;
int &rIntRef = value;

Bjoern
October 10, 2007
BLS wrote:
> The problem is ;
> //C++
> int value = 100;
> int & rIntRef = value;

//C
int value = 100;
int *rIntRef = value;

Regards, Frank
October 10, 2007
0ffh wrote:
> //C
> int value = 100;
> int *rIntRef = value;

Okay, but only if you don't mind the core dump! =)

//C
int value = 100;
int *rIntRef;
rIntRef = &value;
October 10, 2007
0ffh schrieb:
> 0ffh wrote:
>> //C
>> int value = 100;
>> int *rIntRef = value;
> 
> Okay, but only if you don't mind the core dump! =)
> 
> //C
> int value = 100;
> int *rIntRef;
> rIntRef = &value;

int value = 100;
int & rIntRef = value;
if (rIntRef == 100)
  // be ashured
rIntref = 101

This is why I like refrences, they behave like an alias-name. (and are Not as dangerous as pointers :)
Thanks Bjoern
October 10, 2007
BLS wrote:
> This is why I like refrences, they behave like an alias-name. (and are Not as dangerous as pointers :)

To quote Friedrich Nietzsche:
"The secret to find the most pleasure in life, is to live dangerously."

=)

Regards, Frank
October 10, 2007
0ffh schrieb:
> BLS wrote:
>> This is why I like refrences, they behave like an alias-name. (and are Not as dangerous as pointers :)
> 
> To quote Friedrich Nietzsche:
> "The secret to find the most pleasure in life, is to live dangerously."
> 
> =)
> 
> Regards, Frank
LOL;
Man,  I am allready married.
October 11, 2007
Sean Kelly wrote:
> Walter Bright wrote:
>> Bug fixes. New (and very modest) C++ interface. Library module overhauls by Andrei Alexandrescu. Brad Roberts is working behind the curtain to get phobos development much better organized.
> 
> 
> And to think I just patched some code and makefiles last night to work around some of these bugs :-)  Nice work!
> 
> On a semi-related note, a Tango release is planned for today.  In fact, it's already packaged and ready to go.  So I'll give DMD 1.022 support a look this evening and perhaps we'll re-release tomorrow if any changes are necessary.  I have jury duty so I won't be able to get to it today.

So it took me a bit longer than expected to get to this.  Things were also a bit complicated by the fact the the timestamps for most of the files had changed even though the files themselves were untouched. Fortunately, my diff tool was up to the task, and it seems there are no runtime changes necessary for Tango in this release.  I love it when that happens :-)


Sean
1 2 3 4 5 6 7 8 9 10 11
Next ›   Last »