Second Draft: ref for Variable Declarations

Walter Bright newshound2 at digitalmars.com
Fri May 3 07:57:34 UTC 2024


On 5/2/2024 9:19 PM, Nicholas Wilson wrote:
> Your example that purports to show the utility of the new feature is already 
> accomplishable by `alias`
> ```d
> void pop87(int line, const(char)* file)
> {
>      alias g = global87;
>      // ... use `g`
> ```

Not exactly. Accessing global variables takes a varying number of instructions 
depending on the memory model. Using a ref variable makes it a simple pointer. 
An alias is fundamentally different, although in trivial cases they can appear 
to be the same.

There are three ways to refer to a value

1. by value
2. by reference
3. by name

Alias is by name, you'll see it also in ref, alias, and value parameters to 
function templates.




More information about the dip.development mailing list