any news on const/invariant?
Bill Baxter
dnewsgroup at billbaxter.com
Thu Nov 29 12:31:09 PST 2007
Oskar Linde wrote:
> Walter Bright wrote:
>> Oskar Linde wrote:
>>> Ok, but it is then unfortunate that having two constants:
>>>
>>> invariant a = 1;
>>> const b = 2;
FWIW my naive expectation was that "invariant a = 1" would give you
something you can't take the address of because it may be inlined or
whatever, whereas "const b=2" I expected to be deref-able and actually
live somewhere in memory.
I think the reason is that I had come to understand 'invariant' as being
the one that lets the compiler do sneaky optimizations and make
assumptions that something really will not change ever, whereas const
merely says the reference you have isn't changing but someone else might
be changing it.
> I know you are of that view, and your strongest association with the
> word "readonly" is in the sense of ROM, but I do believe you are in a
> minority. Uses of read-only in the context of access attributes,
> registers and views are well established and maps very well to the
> current "const" keyword. I expanded those arguments in:
I agree the meaning of "readonly" is perfect, (and how on earth could it
mean "put this data in ROM"? It's physically impossible unless D was
some kind of EPROM burning software). BUT those three extra letters
over "const" do bother me. Because in function signatures it can often
be repeated 5 or more times. So though probably in the minority, I'd
rather have it become "ro" if it's going to change. There is some other
language that uses that. I can't remember which one.
But anyway I'm not holding my breath waiting for Walter to make such a
change.
> The only reason I keep posting about this must be because I am an
> incurable optimist. Or maybe I am just too stubborn to realize I've
> lost. Or maybe I'm just stuck at the romantic idea that the const issue
> could be resolved in a way that leaves const meaning constant. :P
Or D) all of the above. :-)
--bb
More information about the Digitalmars-d
mailing list