logical const is a subset of transitive const

Janice Caron caron800 at googlemail.com
Fri Sep 14 14:40:11 PDT 2007


On 9/14/07, Steven Schveighoffer <schveiguy at yahoo.com> wrote:
> const int* f(); // is f const, or is it returning a const int*?

I tried playing around with compiling things like this. In D2.0, it
definitely looks like the compiler interprets this as meaning that f
is const.

Maybe it also means the return value is /also/ const? As in, it
returns const(int *). I haven't checked. Either way, weird.


> If that is the reason, then I say use const, and put it after the func
> declaration, like in C++.  May look weird, but it's unambiguous.

There's also the possibilities of:
int * const f()
int * const(f())

These would be more in line with D's "functional notation" for const,
as opposed to C's postfix notation.



More information about the Digitalmars-d mailing list