Setting a pointer to NULL in Arduino library - error: ‘NULL’ was not declared in this scope I am writing my own library for using with my Arduino. In my code, if I set a pointer I have declared to NULL, such as

int *ptr=NULL;


I get the error

error: ‘NULL’ was not declared in this scope


I need to initialize it to NULL as I am using pointers to implement a list.

If I use NULL directly in the program in the IDE, I do not get this error. This seems to be happening only when it is a part of the library code.

How do I correct this? Is there any alternative keyword to use? Or do I have to include some library?

Thank you.
You should make sure your header includes the stddef.h header, which holds all these standard definitions (hence its name):

#include &lt;stddef.h&gt;