September 22, 2015
On Tuesday, 22 September 2015 at 15:33:40 UTC, Ola Fosheim Grøstad wrote:
> On Tuesday, 22 September 2015 at 15:11:55 UTC, Kagamin wrote:
>> Another C feature you didn't know about: the standard allows to create a mutable pointer to const data and mutate it.
>
> I didn't? Of course I did. In C++ other threads can write to const objects. The function receiving a const objects is not supposed to write to const. Const cast is supposed to be used for calling legacy const interfaces without a const signature.

Of course you didn't. In C you can mutate const object without cast. But it's not an issue because it's not what is usually done and usually const works as expected.
September 22, 2015
On Tuesday, 22 September 2015 at 15:53:22 UTC, Kagamin wrote:
> Of course you didn't. In C you can mutate const object without cast. But it's not an issue because it's not what is usually done and usually const works as expected.

No. Const objects are read only. Writing to read only objects would be undefined behaviour. I.e. illegal and could make your computer crash if it is a hardware register or memory that does not allow writing. Const references can exhibit aliasing if they aren't marked as "restrict":

http://stackoverflow.com/questions/457441/does-restrict-help-in-c-if-a-pointer-is-already-marked-const

September 23, 2015
On Tuesday, 22 September 2015 at 16:24:33 UTC, Ola Fosheim Grøstad wrote:
> On Tuesday, 22 September 2015 at 15:53:22 UTC, Kagamin wrote:
>> Of course you didn't. In C you can mutate const object without cast. But it's not an issue because it's not what is usually done and usually const works as expected.
>
> No. Const objects are read only. Writing to read only objects would be undefined behaviour.

That's why there's no choice other than trust developer to do the expected thing.
1 2 3
Next ›   Last »