P
prashant.khade1623
I am not getting the exact idea.
Can you please explain me with an example.
Thanks
Can you please explain me with an example.
Thanks
But is is better to dereference a NULL pointer than uninialized pointer or aMorris said:Please state your question in the body of your article - thanks.
A NULL pointer is not /for/ dereferencing. Setting a pointer to
NULL indicates that the pointer does not point to a usable value
and should not be dereferenced.
No, I'm not prepared to guarantee this, but it happens on every machine I'veMorris said:Umm - are you prepared to _guarantee_ that dereferencing a null
pointer will result in a crash on _every_ system, or are you
engaging in a bit of wishful thinking?
even NULL?Morris said:Then I think we're in basic agreement. In many of the
environments I've worked in it's possible to access every address
even though there may not be anything (memory or device) at that
address - without consequence other than retrieval of (usually)
an all-ones value.
I am not getting the exact idea.
Can you please explain me with an example.
Thanks
I am not getting the exact idea.
Can you please explain me with an example.
Joachim Schmitz said:No, I'm not prepared to guarantee this, but it happens on every machine
I've come accross so far.
And dereferencing dangling pointers is by far less 'reliable' when it
comes to crash a machine at a predictable spot.
Joachim said:No, I'm not prepared to guarantee this, but it happens on every machine I've
come accross so far.
And dereferencing dangling pointers is by far less 'reliable' when it comes
to crash a machine at a predictable spot.
Morris Dovey wrote:
No, I'm not prepared to guarantee this, but it happens on every machine I've
come accross so far.
[/QUOTE]No, I'm not prepared to guarantee this, but it happens on every machine
I've come accross so far.
Well, you haven't come across many machines, then - not even x86s, it
seems.
But is is better to dereference a NULL pointer than uninialized
pointer or a pointer that points to something that is no longer
valid. Better, because easier do spot (the probtram will
crash right there) and to debug (hunting dangling pointers is
a pain in the proverbial, as the program quite likely crashes
at a totally unrelated place). So there's a good reason to
(re-)initialize a pointer to NULL.
Richard Heathfield said:Well, you haven't come across many machines, then - not even x86s, it
seems. I have an x86 currently sat about three yards away from my desk,
admittedly a rather old one but there's nothing particularly special about
it. If you run a program on this computer that derefs NULL, well, I can't
tell you what will happen, obviously, because the behaviour is UB, but
*very often* what happens is that the program runs to completion and then
a little message is displayed at the end. I can't quite remember the
precise text, but basically it tells you about the null pointer deref. I
don't guarantee that a null pointer deref *won't* crash the program on
such a system, of course. But very often it does not.
Jack Klein said:Really? Chapter and verse, please. Where does the C standard make
one of these two operations more undefined than the other?
Kenneth said:Joachim Schmitz wrote:
And that's my main point. You may win something, but won't loose anything,Now, that doesn't mean that (re-)initializing pointers to NULL is a
bad idea. It certainly is "better" than leaving uninitialized or
dangling pointers.
Re-read and tell me where I claimed this being mandated by the standard. IJack said:Really? Chapter and verse, please. Where does the C standard make
one of these two operations more undefined than the other?
? Most (UNIX and other) _Servers_ will kill a program that derefence a NULLAt least 90% (probably more) of the computing devices in the world
executing C code at any given time have no hardware memory protection,
and most likely won't trap at all.
Another desktop chauvinist.
True. But marking the invalid ones invalid by setting them to NULL is partThere's a much better reason to keep track of when pointers are and
are not valid.
Jack said:Really? Chapter and verse, please. Where does the C standard make
one of these two operations more undefined than the other?
At least 90% (probably more) of the computing devices in the world
executing C code at any given time have no hardware memory protection,
and most likely won't trap at all.
Another desktop chauvinist.
There's a much better reason to keep track of when pointers are and
are not valid.
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.