Glossary · Automation software engineering and architecture
Null pointer
Also known as: Null reference
German: Nullzeiger
In programming, a null pointer is a pointer or reference that deliberately points to no valid object; dereferencing it is an error that typically crashes the program or, in some languages, causes undefined behavior.
- Software engineering
In one sentence
A null pointer refers to no valid object; dereferencing it is an error that usually crashes the program or causes undefined behavior.
Example
A PLC function block receives a reference to an axis that was never assigned, dereferences it and the controller goes to stop with an access violation.
How it applies
- Engineering: Code should check pointers and references before use or use language features that make null impossible. Newer IEC 61131-3 environments also support references and pointers, with the same risks as in C.
- Verification: Static code analysis detects many possible null dereferences; coding standards for embedded software require checks at interfaces.
- Documentation: If a controller stops because of an access violation, the diagnostic message and its meaning belong in the troubleshooting documentation, together with guidance to contact service rather than just restarting.
Null pointer vs. dangling pointer
A null pointer points to nothing on purpose and can be tested for. A Dangling pointer still holds an address, but the object there no longer exists, so a simple check does not reveal the error.