On Mon, Sep 17, 2012 at 5:00 PM, Jakub Jermar <[email protected]> wrote:
> On 17.9.2012 16:52, Ján Veselý wrote:
>> That is the point. If a function takes const type * as an argument, it
>> indicates that it does not modify the instance.
>
> I hope I am not misguided, but I think this is simply not true when put
> like that. I believe it only indicates it will not modify the instance
> using _that_ const type * pointer, but does not indicate it will not
> modify it using another non-const pointers. This is also the reason
> behind my doubts about the first mail.

yes I agree. It will not use the provided pointer to modify the instance.
The idea is not to guarantee that the instance won't be modified. The
idea is to provide information to the programmer that the given
function does not modify the instance (as you pointed out this is not
guaranteed). If a function modifies the provided instance, it should
indicate it by using non-const pointer. Even if it gets a pointer to
the same instance from some other source (hopefully by accident,
designing functions to take const pointers and get RW pointer to the
same instance is the same thing as casting -- we should avoid it). The
rule to use pointers to const instances is not about language
semantics, it's about enforcing coding patterns that make interfaces
clearer and more readable.

jan

>
> Jakub
>
> _______________________________________________
> HelenOS-devel mailing list
> [email protected]
> http://lists.modry.cz/cgi-bin/listinfo/helenos-devel

_______________________________________________
HelenOS-devel mailing list
[email protected]
http://lists.modry.cz/cgi-bin/listinfo/helenos-devel

Reply via email to