On 8/15/2014 10:45 AM, H. S. Teoh via Digitalmars-d wrote:
Nah, the better practice is to write const(int) instead of const int,
which is ambiguous when used to specify a function's return value.

For example,

        const int func();

is *not* the same as:

        const(int) func();

which can be quite a nasty surprise for the unwary. My personal practice
is to always write const(int) everywhere, thus eliminating the
ambiguity.


const without parentheses is a 'storage class'.
const with parentheses is a 'type constructor'.

Storage classes apply to the symbol being declared, and hence the type of the symbol.

Type constructors apply to the type in the ( ).

It is not ambiguous from a semantic or syntactic point of view, but it appears to be ambiguous for those coming from C++. This was discussed at length a few years ago, but no solution emerged that didn't make things much worse.

Reply via email to