any news on const/invariant?

0ffh frank at frankhirsch.youknow.what.todo.net
Wed Nov 28 14:45:30 PST 2007


Walter Bright wrote:
> Ok, let's assume C++ is intuitive, consistent, and logical. Given:
> 
> const int *p;
> 
> what makes more logical, intuitive sense?
> 
> 1) p is a non-constant pointer to const int?
> 2) p is a const pointer to a non-const int?
> 3) p is a const pointer to a const int?
> 
> I doubt you'll get a consistent answer from programmers who aren't 
> already very used to the wacky C++ semantics.

Okay, you can take me as one sample, I suck at C++! Hah!
I haven't even followed the thread very closely... =)
I'd expect... hmmm... option 1: I'd think *p is an int (p being
the pointer), it's just not an int but a const int.
But I really couldn't be sure, and would probably look it up...

Btw. wouldn't it be "const int* p" in D?
Just changing the spacing makes me re-think my answer! Argh!

> I doubt people will be confused by it for more than 5 minutes, and then 
> it will make sense. I find the D version of const much more intuitive, 
> from a logical, consistency point of view, than the C++ one.

I guess now I'll have to go and look up both!

>> So I guess I can see people getting used to this.  So the question 
>> again becomes why allow the at-the-end syntax too?  Isn't one syntax 
>> enough? 
> 
> It's a good question. Note that D allows both C-style and D-style array 
> declarations. It makes it easier to convert C code over to D code.

Actually, when it comes to array declaration style, I wouldn't care if the
old style was dropped in D. The new one works fine (for me), and there are
some good arguments for having just OWTDI.

regards, frank





More information about the Digitalmars-d mailing list