LWN.net Logo

Null pointers, one month later

Null pointers, one month later

Posted Aug 23, 2009 8:23 UTC (Sun) by oak (guest, #2786)
Parent article: Null pointers, one month later

"A new function pointer added to a structure will be silently set to null
by the compiler in every declaration which does not include an explicit
initialization for that pointer."

Only (structure or other) variables that are static (global or static in
the local scope) are guaranteed by C to be initialized to zero. Compiler
does this by storing them into BSS which is zeroed by the OS on process
startup.

Other variables *may* be zero if their storage happens to be in a part of
heap or stack that hasn't been used earlier by the process. And even this
happens only on OSes that initialize the new pages to zero. Otherwise the
variables contain a "random" value.


(Log in to post comments)

Copyright © 2013, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds