On 06/09/2015 09:36 PM, Dennis Ritchie wrote: > But I can not do so: > > enum int[][int][int] ctHash = init_ctHash(5); > > ctHash = merge(ctHash, init_ctHash(6)); > > I have a question: why variables may not be initialized more than once? > Why can't they to resave at compile time?
My phrasing was off: By definition, initialization happens once. :) What I meant is, once initialized, a compile-time variable cannot be reassigned. The reason is, to effect compile time evaluation, one needs to use 'enum' (or 'static const') but 'enum' is a literal, i.e. it cannot be modified.
As I've shown, it is possible to use an expression that will be used as the value of the compile-time variable. As long as it is evaluable at compile time, the expression can be arbitrarily complex.
Ali