pointers, functions, and uniform call syntax
Era Scarecrow
rtcvb32 at yahoo.com
Thu Sep 6 13:07:06 PDT 2012
On Thursday, 6 September 2012 at 12:00:05 UTC, Artur Skawina
wrote:
> On 09/06/12 13:34, Era Scarecrow wrote:
>> Alright let's go the opposite direction. Give me an example in
>> which passing a variable (by reference to a function) would
>> EVER require it to check the address to see if it was null.
>> Class/allocated objects should fail before the function gets
>> control. ie:
>>
>> void func(ref int i);
>>
>> class X {
>> int i;
>> }
>>
>> X x;
>> int* i;
>> int[10] a;
>>
>> func(x.i); /*should fail while dereferencing x to access i,
>> so never gets to func*/
>> func(*i); //does this count as a lvalue? Probably not,
>> func(a[0]);//none of these three should compile with that in
>> mind
>> func(0);
>>
>> Being named variables, and likely non-classes you are then
>> left with mostly local variables, or arrays, or some type of
>> pointer indirection issue. But ever case I come up with says
>> it would fail before the function was called.
>
> Both '*i' and 'a[0]' count. (Even '0' could be made to work as
> a 'const ref' arg, but i'm not sure if that would be a good
> idea)
I wasn't sure about *i. I can see it going either way. *i would
need to be dereferenced first, a[0] would need a bounds check
which then ensures it exists (even if it was dynamic); So
checking an address from ref wouldn't be needed in the func.
More information about the Digitalmars-d
mailing list