Hi Jano,

thanks for producing the initial material for the heated debate :-)
Speaking for myself, I think some clarifications are needed, please see
below.

On 10.9.2012 18:38, Ján Veselý wrote:
> Using pointers is a bit different. It still makes no sense to declare pointer 
> parameters constant, but USING POINTERS TO CONST DATA IS OF GREAT USE. 
> Example:
> 
> int count_something(const struct foo_t *instance);
> 
> const struct foo_t *my_foo = get_foo();
> const int something_count = count_something(my_foo);
> 
> If the data in foo_t changed after a call to this function it's a bug (memory 
> corruption, ...).

What if count_something() casts the instance variable to a (struct foo_t
*) pointer and uses that pointer to modify the data? Is such a cast
allowed? C99 in 6.7.3 (5) says that:

 If an attempt is made to modify an object defined with a const-
 qualified type through use of an lvalue with non-const-qualified type,
 the behavior is undefined.

What if count_something() can get the address returned by get_foo() from
elsewhere?

Jakub

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

Reply via email to