Topic: Quick Question about null Pointer Assignments
Author: akv@srl03.cacs.usl.edu (Anil Vijendran)
Date: 1995/04/21 Raw View
I'd suggest you pick up the code for a smart pointer (a two year old
Cay Horstmann's article in C++ Report for example) and replace all
your pointers with this smart one. Modify the dereference operations
to do null pointer checking... I've had decent success at it (whew!
I'm happy my DOS days are over).
>>>>> On Wed, 19 Apr 1995 09:32:10 GMT,
FallonJB95%cs29@cadetmail.usafa.af.mil (Josh Fallon) said:
Josh> Hello Again, I am in the process of writing a C++ program
Josh> and I have a confusing problem. Whenever the program ends,
Josh> the runtime outputs a "Null Pointer Assignment" to the
Josh> screen. OK, I thought, Its a problem with my constructer or
Josh> destructer in the Classes I made. Well, I traced through
Josh> the program, and found that all my destructors were called
Josh> correctly. This message occurs _after_ all destructers were
Josh> called though. I went through several times, and have NO
Josh> idea what is causing this assignment. If anyone have any
Josh> ideas, or has seen this problem earlier, please let me know
Josh> by email or posting. Thanks a lot. Blue Skies! --Josh
Josh> Fallonjb95%cs29@cadetmail.usafa.af.mil
--
Anil
___________________________________________________________________________
Anil K Vijendran USL Box 43007, Lafayette, LA 70504-3007
akv@cacs.usl.edu (318) 232-5502 [H]
Author: udin@localnet.com (David Udin)
Date: 1995/04/21 Raw View
> >>>>> On Wed, 19 Apr 1995 09:32:10 GMT,
> FallonJB95%cs29@cadetmail.usafa.af.mil (Josh Fallon) said:
>
> Josh> Hello Again, I am in the process of writing a C++ program
> Josh> and I have a confusing problem. Whenever the program ends,
> Josh> the runtime outputs a "Null Pointer Assignment" to the
> Josh> screen. OK, I thought, Its a problem with my constructer or
This is not specifically a C++ issue.
(I take it you are using some Borland compiler.) Under the Borland
run-time environment the null pointer is set to point to a particular bit
pattern. When your program exits, the environment checks to see whether
that bit pattern has been disturbed. If so, it prints that message. Write
references through a null pointer, among (many) other things, can cause
the problem.
--
David Udin
udin@localnet.com
Consulting and Training in C++ and Object Technology
716-838-4525
Author: FallonJB95%cs29@cadetmail.usafa.af.mil (Josh Fallon)
Date: 1995/04/21 Raw View
In article <3n5n8s$3q4@vbohub.vbo.dec.com> johnston@caiman.enet.dec.com (Ian Johnston) writes:
>In article <FallonJB95%cs29.153@cadetmail.usafa.af.mil>,
>FallonJB95%cs29@cadetmail.usafa.af.mil (Josh Fallon) writes:
>>problem. Whenever the program ends, the runtime outputs a "Null Pointer
>>Assignment" to the screen. OK, I thought, Its a problem with my
>You get this message after the program ends because the compiler (Borland
>C++ in this case, right?) makes a check--after your program has
>finished-- to see if the contents of low memory addresses have changed
>from the values they had before your program started.
>What it means is that, somewhere during your program, you have
>assigned through a pointer to a low memory address, probably a
>NULL pointer.
>As a general point: is anyone working on a FAQ for PC C++ compilers?
>Ian
>--
>Consulting for Digital Equipment Corp johnston@caiman.enet.dec.com
> (33) 92.95.51.74
Thanks for the help from everyone. I see where I went wrong in setting the
pointer(or lack of). I was confused about where to look for the bug because
the message appeared at the end of the program. Also, I guess that this
post was probably in the the wrong newsgroup and should of been in the
comp.lang.c++. For the people who pointed it out, I appreciate it. Anyway,
I'll probably be posting quite a bit more questions there. Thanks again.
Blue Skies!
--Josh
Fallonjb95%cs29@cadetmail.usafa.fa.mil
Author: johnston@caiman.enet.dec.com (Ian Johnston)
Date: 1995/04/20 Raw View
In article <FallonJB95%cs29.153@cadetmail.usafa.af.mil>,
FallonJB95%cs29@cadetmail.usafa.af.mil (Josh Fallon) writes:
>problem. Whenever the program ends, the runtime outputs a "Null Pointer
>Assignment" to the screen. OK, I thought, Its a problem with my
You get this message after the program ends because the compiler (Borland
C++ in this case, right?) makes a check--after your program has
finished-- to see if the contents of low memory addresses have changed
from the values they had before your program started.
What it means is that, somewhere during your program, you have
assigned through a pointer to a low memory address, probably a
NULL pointer.
As a general point: is anyone working on a FAQ for PC C++ compilers?
Ian
--
Consulting for Digital Equipment Corp johnston@caiman.enet.dec.com
(33) 92.95.51.74
Author: jamshid@ses.com (Jamshid Afshar)
Date: 1995/04/20 Raw View
Redirected to comp.os.msdos.programmer. Please remember comp.std.c++
is intended for discussion directly related to the (evolving) C++
Standard.
In article <742439049wnr@archcrst.demon.co.uk>,
John Ballam <john@archcrst.demon.co.uk> wrote:
>In article: <FallonJB95%cs29.153@cadetmail.usafa.af.mil> FallonJB95%cs29@cadetmail.usafa.af.mil
>> I am in the process of writing a C++ program and I have a confusing
>> problem. Whenever the program ends, the runtime outputs a "Null Pointer
>> Assignment" to the screen. OK, I thought, Its a problem with my
>> constructer or destructer in the Classes I made. Well, I traced through the
>> program, and found that all my destructors were called correctly. This
>> message occurs _after_ all destructers were called though. [...]
>
>You don't say which compiler you are using, but I have encountered this
>problem when teaching C++ using Borland 3.1 under DOS. Despite giving
>several plausible explanations to my students, I could never figure out
>what caused it either :-)
It means that somewhere in your program (not necessarily in a ctor or
dtor) you are dereferencing and writing data to a null pointer (or a
pointer whose value is near 0x0000). Borland's final exit code
detects and reports this error in the smaller memory models (it
probably would be crashing in a larger memory model or under other
operating systems).
See the following for debugging help. It's from Jeffrey Carlyle's
comp.os.msdos.programmer (hint, hint) FAQ (at
ftp://rtfm.mit.edu/pub/usenet/comp.os.msdos.programmer):
7.10 - What's this "null pointer assignment" after my C program
executes?
Somewhere in your program, you assigned a value _through_ a pointer
without first assigning a value _to_ the pointer. (This might have
been something like a strcpy() or memcpy() with a pointer as its
first argument, not necessarily an actual assignment statement.)
Your program may look like it ran correctly, but if you get this
message you can be certain that there's a bug somewhere.
Microsoft and Borland C, as part of their exit code (after a call to
exit() or a return from your main function), check whether the
location 0000 in your data segment contains a different value from
what you started with. If so, they infer that you must have used an
uninitialized pointer. This implies that the message will appear at
the end of execution of your program regardless of where the error
actually occurred.
To track down the problem, you can put exit() calls at various spots
in the program and narrow down where the uninitialized pointer is
being used by seeing which added exit() makes the null-pointer
message disappear. Or, if your program was compiled with small or
medium models, which use 16-bit data pointers, tell the debugger to
set a watch at location 0000 in your data segment. (If data
pointers are 32 bits, as in the compact and large models, a null
pointer will overwrite the interrupt vectors at 0000:0000 and
probably lock up your machine.)
Under MSC/C++ 7.0, you can declare the undocumented library function
extern _cdecl _nullcheck(void);
and then sprinkle calls to _nullcheck() through your program at
regular intervals.
Borland's TechFax document TI726 discusses the null pointer
assignment from a Borland point of view. It's one of many documents
downloadable as part of
<ftp://oak.oakland.edu/pub/msdos/turbo-c/bchelp10.zip>
<ftp://garbo.uwasa.fi/pc/turbopas/bchelp10.zip>
Author: stidev@gate.net (Solution Technology)
Date: 1995/04/19 Raw View
Josh Fallon (FallonJB95%cs29@cadetmail.usafa.af.mil) wrote:
:
: Hello Again,
: I am in the process of writing a C++ program and I have a confusing
: problem. Whenever the program ends, the runtime outputs a "Null Pointer
: Assignment" to the screen. OK, I thought, Its a problem with my
: constructer or destructer in the Classes I made. Well, I traced through the
: program, and found that all my destructors were called correctly. This
: message occurs _after_ all destructers were called though. I went through
: several times, and have NO idea what is causing this assignment. If anyone
: have any ideas, or has seen this problem earlier, please let me know by
: email or posting. Thanks a lot.
: Blue Skies!
It means that somewhere in the program you assigned through a pointer that
had a NULL value, or did a string operation through a NULL string pointer.
Since you are not using an operating system with memory protection
you could use something like SoftIce to help you locate it.
Ken Walter
Author: john@archcrst.demon.co.uk (John Ballam)
Date: 1995/04/19 Raw View
In article: <FallonJB95%cs29.153@cadetmail.usafa.af.mil> FallonJB95%cs29@cadetmail.usafa.af.mil
(Josh Fallon) writes:
>
>
> Hello Again,
> I am in the process of writing a C++ program and I have a confusing
> problem. Whenever the program ends, the runtime outputs a "Null Pointer
> Assignment" to the screen. OK, I thought, Its a problem with my
> constructer or destructer in the Classes I made. Well, I traced through the
> program, and found that all my destructors were called correctly. This
> message occurs _after_ all destructers were called though. I went through
> several times, and have NO idea what is causing this assignment. If anyone
> have any ideas, or has seen this problem earlier, please let me know by
> email or posting. Thanks a lot.
> Blue Skies!
> --Josh
> Fallonjb95%cs29@cadetmail.usafa.af.mil
>
>
You don't say which compiler you are using, but I have encountered this
problem when teaching C++ using Borland 3.1 under DOS. Despite giving
several plausible explanations to my students, I could never figure out
what caused it either :-)
--
---------------------------------------------------------------------------
| John Ballam EMail john@archcrst.demon.co.uk |
---------------------------------------------------------------------------
Author: FallonJB95%cs29@cadetmail.usafa.af.mil (Josh Fallon)
Date: 1995/04/19 Raw View
Hello Again,
I am in the process of writing a C++ program and I have a confusing
problem. Whenever the program ends, the runtime outputs a "Null Pointer
Assignment" to the screen. OK, I thought, Its a problem with my
constructer or destructer in the Classes I made. Well, I traced through the
program, and found that all my destructors were called correctly. This
message occurs _after_ all destructers were called though. I went through
several times, and have NO idea what is causing this assignment. If anyone
have any ideas, or has seen this problem earlier, please let me know by
email or posting. Thanks a lot.
Blue Skies!
--Josh
Fallonjb95%cs29@cadetmail.usafa.af.mil