In article <1150917030.618581.196250
@m73g2000cwd.googlegroups.com>,
aj********@yahoo.com
says...
//C++
char* p;
while (*p)
{}
/* Access violation. How can I check to see if p is valid? Thanks.*/
There is no portable way to check whether a pointer is
valid. For that matter, there's no portable definition of
what constitutes a valid pointer in the first place.
One obvious alterative is to use smart pointer class of
some sort instead of using a raw pointer to start with.
The smart pointer class can include code to check whether
its pointer has been initialized or (more common)
initialize its pointer so it's always been assigned a
value. Of course, this still isn't a panacea -- if you do
something equivalent to:
char *p = (char *)1;
chances are you'll end up with a pointer that's still
invalid -- but for that to happen, you have to do it
explicitly, rather than it happening by default.
--
Later,
Jerry.
The universe is a figment of its own imagination.