R
Raymond Martineau
Gernot Frisch said:Catalin Pitis said:Definitely agree with you there! While having a teacher (for anything in
life really) will make you learn faster, still there's no need for the
teacher. I've yet to find a book which has a good explanation on why:
int *p_k;
*p_k = 4;
is illegal.
When you find it, tell me . I'm curious.
Don't understand: Is there no book that tells you that it's illegal? I'm
gonna write one. Title:
"Dereferencing an uninitialized pointer is illegal".
Content:
Dereferencing an uninitialized pointer is illegal. Example:
int* p_k; *p_k=4; [1]
References:
[1] JKob in comp.lang.c++, 27.10.2004
Am I gonna be rich?
-Gernot
It should be a missundertanding . By illegal I meant that the compiler
doesn't allow me to do it. But I'm allowed to do it. I surely wouldn't do it
.
The compiler generally issues a warning in that case. It doesn't block you
from doing it (since the standard merely says it's undefined rather than an
error), but alerts you in case you forgot to do somethine first.
The piece of code is only stated to be undefined under general standards. A
compiler doesn't complain because there is a chance that the variable may
be initialized somehow (but I doubt it). As a result, the only problems
you encounter will be at run-time (or in the case of old dos programs, a
"null pointer assignment" message on shutdown.)