define should be the keyword for manifest constants

Jason House jason.james.house at gmail.com
Thu Dec 13 08:12:54 PST 2007


Gilles G. Wrote:

> "define" makes no sense if you want to declare a "const" member function.
> It could be of great use for manifest constant, but you'd still have to find a word for other const cases...

I have absolutely no problem with different logical things using different keywords.  IMHO, shoe-horning keywords to fit a new and unanticipated case is not desirable.  I'd hate to see manifest constants without types.  I'd probably vote against define simply because I associate it with a loss of type info (probably the influence of C)

I'm not yet convinced in what cases manifest constants are important.  I think most headers defining integral constants should be enums instead of (C) #define.  That's probably one reason the enum keyword gained some traction.

If manifest constants go beyond integral types, is it better to extend enums to contain more types than just integer?  Or is it better to use another keyword?  I kind of like the pure proposal because it does fit in with the concept of pure functions.  With the whole const vs. invariant thing, even const as a keyword doesn't make a whole lot of sense (it'd really be invariant).

Of course, I wonder why the compiler can't just determine which constants should be manifest and which need allocation.  It could very well be that we just say define manifest constants like any other constants and then *if* you don't trust the compiler to get it right, use an attribute to force the compiler in the right direction.

manifest{
  const int A = ...;
  const int B = ...;
  const int C = ...;
  ...
}



More information about the Digitalmars-d mailing list