compile time 'address'
Dominic Jones
dominic.jones at gmx.co.uk
Thu Nov 29 17:59:54 UTC 2018
Hello Steve,
Thank you for your comments. A couple of replies:
On Thursday, 29 November 2018 at 16:29:00 UTC, Steven
Schveighoffer wrote:
> 1. No you cannot read c0 or c1 at compile time, because they
> are runtime values. You can fix this by changing them to
> immutable or enum.
The variables are deliberately 'auto' rather than 'auto
constexpr' as per the C++ example, so I do wish to preserve that
in the D example. Nevertheless, in C++ querying (at least to
perform comparison) the sudo-address, whatever it is (perhaps,
behind the scenes it is simply a stack frame offset), is
permitted.
> 2. D doesn't like you taking the address of compile-time
> values, but the error message is really bad.
>
> If I do this:
>
> auto cmp(T, U)(const T t, const U u) // note, no ref
> {
> return t == u; // note, change to value not address
> }
Presumably, this is now simply comparing values held by the
variables, rather than the sudo-address of the original variables
as per the C++ example?
More information about the Digitalmars-d
mailing list