example of pointer usefulness in D
Ali Çehreli via Digitalmars-d
digitalmars-d at puremagic.com
Tue Oct 21 13:57:40 PDT 2014
On 10/21/2014 01:15 PM, bearophile wrote:
> Ali Çehreli:
>
>> - References to any local data because 'ref' is only for parameters
>> and return types.
>>
>> int a;
>> int b;
>> int* r = (condition ? &a : &b); // r must be a pointer
>> *r = 42;
>
> Regarding this example, this works:
>
> void main() {
> int a, b;
> bool condition;
> (condition ? a : b) = 42;
> }
>
> Bye,
> bearophile
Yes but that doesn't scale when we need to use it again:
(condition ? a : b) = 42;
foo(condition ? a : b);
// ...
Ali
More information about the Digitalmars-d
mailing list