const int vs. int const
H. S. Teoh via Digitalmars-d
digitalmars-d at puremagic.com
Fri Aug 15 10:45:19 PDT 2014
On Fri, Aug 15, 2014 at 05:05:53PM +0000, John via Digitalmars-d wrote:
> This may be a silly issue, but I recently read the better practice is
> to begin with the variable type followed by const keyword, but that
> order doesn't work in D. Is that intentional?
>
> int const minWage = 11; //Error: no identifier for declarator int
> //const int minWage = 11; //works
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.
T
--
"No, John. I want formats that are actually useful, rather than over-featured megaliths that address all questions by piling on ridiculous internal links in forms which are hideously over-complex." -- Simon St. Laurent on xml-dev
More information about the Digitalmars-d
mailing list