const int vs. int const

Sean Kelly via Digitalmars-d digitalmars-d at puremagic.com
Fri Aug 15 10:16:44 PDT 2014


On Friday, 15 August 2014 at 17:05:55 UTC, John 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

It is intentional, and I think this "best practice" idea doesn't
apply to D in the same was as C/C++.  The reason this is an issue
in C/C++ is because "const char *" is equivalent to "char const
*", but once typedefs and templates enter the picture things
start to get confusing.  Since D allows the const qualifier to
use parens to specify what part of the type it applies to, we
don't need to support the C style syntax.


More information about the Digitalmars-d mailing list