digitalmars.D - const & invariant at global scope
- Steve Teale (4/4) Jul 06 2007 At global scope, is there any difference between
- torhu (11/18) Jul 09 2007 If I'm not mistaken, they are more or less the same. const has the
At global scope, is there any difference between const int n = 42; invariant int n = 42; If not, which is the preferred style in translated C header files and such?
Jul 06 2007
Steve Teale wrote:At global scope, is there any difference between const int n = 42; invariant int n = 42; If not, which is the preferred style in translated C header files and such?If I'm not mistaken, they are more or less the same. const has the advantage of being 1.x compatible. invariant has the advantage of possibly being optimized away, and not take up storage space. But the current implementation stores invariants. I'm not sure if consts will always have to be stored or not, but currently they are. 'final' variables are guaranteed to take up space, and don't work with D 1.0. The best way if you've got more than a few constants, would be to use enums. enums don't take up any space. If you don't want to use enums, I'd use consts for now.
Jul 09 2007