Re: Plz explain me the following code
- From: Phil Carmody <thefatphil_demunged@xxxxxxxxxxx>
- Date: Sat, 26 Sep 2009 11:08:15 +0300
Kenneth Brody <kenbrody@xxxxxxxxxxx> writes:
jameskuyper wrote:
[...]
The modification I'm talking about is the one Kenneth Brody suggested
in his message with the header "Date:Thu, 24 Sep 2009 13:17:54 -0400":
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".
The essence of what I'm saying is that this modification is poorly
specified. I don't see any good way to improve it, either, or I would
have suggested one.
Note that I wasn't actually proposing a well-thought-out idea for an
actual change to C. It was mostly an off-the-cuff reply to a thread
which had started going towards "why does C even allow UB ... UB ==
bad language design".
And, thinking a little more about it, some UB doesn't even involve the
host. For example, fclose() on an invalid FILE*, or free() with a
pointer not from malloc() and friends. (Yes, the host may get
involved if the pointer itself is not valid, but what happens with a
valid pointer but just not pointing to what is expected?)
FILE* fp=fopen("foo", "r");
FILE* fp2=malloc(sizeof(*fp2));
memcpy(fp2, fp, sizeof(*fp2));
fclose(fp2);
fp2 of course does point to *what* was expected, it's just not *where*
it was expected.
Phil
--
Any true emperor never needs to wear clothes. -- Devany on r.a.s.f1
.
- Follow-Ups:
- Re: Plz explain me the following code
- From: Kenneth Brody
- Re: Plz explain me the following code
- References:
- Plz explain me the following code
- From: manish sahu
- Re: Plz explain me the following code
- From: Keith Thompson
- Re: Plz explain me the following code
- From: Kenny McCormack
- Re: Plz explain me the following code
- From: Seebs
- Re: Plz explain me the following code
- From: Kenny McCormack
- Re: Plz explain me the following code
- From: Seebs
- Re: Plz explain me the following code
- From: Kenneth Brody
- Re: Plz explain me the following code
- From: Seebs
- Re: Plz explain me the following code
- From: Kenneth Brody
- Re: Plz explain me the following code
- From: jameskuyper
- Re: Plz explain me the following code
- From: Kenneth Brody
- Re: Plz explain me the following code
- From: jameskuyper
- Re: Plz explain me the following code
- From: Keith Thompson
- Re: Plz explain me the following code
- From: jameskuyper
- Re: Plz explain me the following code
- From: Keith Thompson
- Re: Plz explain me the following code
- From: jameskuyper
- Re: Plz explain me the following code
- From: Kenneth Brody
- Plz explain me the following code
- Prev by Date: Re: reverse a string
- Next by Date: Re: About shared object file
- Previous by thread: Re: Plz explain me the following code
- Next by thread: Re: Plz explain me the following code
- Index(es):
Relevant Pages
|