A strange charArray.ptr behavior
Ali Çehreli
acehreli at yahoo.com
Wed Dec 2 21:01:22 UTC 2020
On 12/2/20 12:20 PM, Ferhat Kurtulmuş wrote:
> given the function:
>
> export void ceaser_enc(char* input, ref char* output);
>
> this compiles:
> char* sezar = (new char[65]).ptr;
> ceaser_enc(key, sezar);
>
> this does not compile:
>
> char[] sezar = new char[65];
> ceaser_enc(key, sezar.ptr);
>
> by yielding: "cannot pass rvalue argument cast(char*)sezar of type char*
> to parameter ref char* output"
>
> Why is sezar an rvalue in the second case?
Not 'sezar' but sezar.ptr is an rvalue. Imagine ptr() being a function
that returns a value:
T* ptr() {
// ...
}
That pointer is an rvalue and D disallows binding them to 'ref' parameters.
In the first case, 'sezar' is a local variable, which is an lvalue.
Ali
More information about the Digitalmars-d-learn
mailing list