Re: Plz explain me the following code



jameskuyper <jameskuyper@xxxxxxxxxxx> writes:
Kenneth Brody wrote:
[...]
Perhaps replacing UB with something like "anything left undefined will, on
hosted implementations, behave in a manner consistent with the host"? So,
dereferencing a NULL pointer on Unix can't launch nuclear missiles, since
Unix says it should SEGV.

Basically, "I am not imposing any restrictions, but I do require that you
follow the restrictions placed on you by the host platform".

If the host platform "places" those restrictions, why does the C
standard need to say anything about it? Isn't the host's statement of
those restrictions sufficient?
[...]

Currently, if the host platform specifies that deferencing a null
pointer causes a certain trap that terminates the current program,
a C program that dereferences a null pointer can still behave
arbitrarily badly, because an optimizing compiler is permitted to
assume that no null pointer is ever dereferenced. With Kenneth's
suggestion, this kind of optimization would be prohibited; the
generated code would actually have to dereference the null pointer
and trigger the trap (or behave equivalently, I suppose).

If such a change were made to the language, then (a) optimization
in conforming compilers would become less effective by some unknown
(to me) margin, and (b) existing compilers would have to be modified
to meet the new requirements (with resulting bugs).

--
Keith Thompson (The_Other_Keith) kst-u@xxxxxxx <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
.



Relevant Pages