Is the address-of operator (&) really needed?
Sandeep Datta
datta.sandeep at gmail.com
Fri Jun 1 10:19:17 PDT 2012
>
> 1. It's needed so that you can call it when calling C code.
>
Why can't we just use information from the C function signature
to determine when an address needs to be passed? Why is manual
intervention required here?
> 2. Just because ref is often better than a pointer doesn't mean
> that it's
> never valuable to be able to pass a pointer to a variable.
Passing a pointer may be useful but IMO we should restrict such
things to the unsafe context.
>
> 3. ref doesn't work with variadic templates very well. Take a
> look a
> std.getopt.getopt. It takes pointers, not refs, and there isn't
> a way to make
> it take refs.
>
Is it because getopt() is a C function? If it is see my reply to
your point #1. I'll admit I do not know enough D to understand
what you are saying, some explanation will be helpful.
> 4. & is useful for getting function pointers.
What does the function name represent when not used with an
ampersand? If it doesn't represent anything then I think the
language can be changed to yield an address directly without an
ampersand.
More information about the Digitalmars-d
mailing list