Chris Angelico <> writes:

> On Mon, Feb 19, 2018 at 9:04 PM, Alain Ketterlin
> <> wrote:

>> Look at the C11 standard, section ("Pointers"), 6.5.ยง6-7
>> ("effective types"), and ("Address and indirection operators").
>> It is tiring to constantly correct misunderstandings about pointer
>> casting and dereferencing.
>>> $ cat demo.c; gcc -Wall demo.c; ./a.out
>> [...]
>> If you don't know what undefined behavior is, better avoid C. Your
>> program has UB, anything can happen, including a seemingly sensible
>> result.
> Sure it can. But I don't know what you can mean by "stronger rules" if
> all it says is "that's undefined". Saying that behaviour is undefined
> does NOT mean that C has a stronger type system. I got no errors, not
> even a warning in -Wall mode, so there is no indication that my code
> did something wrong.

I used "stronger rules" in response to the OP claim ("C lets you
manipulate memory freely"). Undefined behavior is part of the semantics
of C, the same way infinite loops of signed-integer overflow are. What
compilers can do about it is a different matter. This is well
documented, those that want to ignore UB are on their own. Anyway, I
think it is irrelevant here. Search for "What every programmer should
know about undefined behavior" if you are interested.

-- Alain.

Reply via email to