:: Re: [DNG] Making sense of C pointer…
Forside
Slet denne besked
Besvar denne besked
Skribent: Rainer Weikusat
Dato:  
Til: dng
Emne: Re: [DNG] Making sense of C pointer syntax.
karl@??? writes:

[...]


> With pointers, you have to handle the special case of null pointers.
> I'm assuming you are omitting it here for brevity, but generally
> change_value() should be something like:
>
> void change_value(int* ptr) {
> if (!ptr) return;
> *ptr = 20000000;
> }


It absolutely shouldn't unless NULL is expected to be valid, used
argument value for some reason. If not, code passing NULL to such a
function is likely erroneous. Forcing the program to abort, preferably
with a core dump, via SIGSEGV will often enable fixing the error easily
and quick. Silently bouncing it out of the function again so that it
further propagates through the program is a terribly risky practice with
literally unpredictable consequences.