user16687: 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.

user4143: You should make sure your header includes the stddef.h header, which holds all these standard definitions (hence its name):
#include <stddef.h>


user10794: 
I am writing my own library for using with my Arduino.

You should really include Arduino.h, i.e.
#include <Arduino.h>

Not only will that define NULL for you, but you also get the other standard Arduino functions like digitalRead, pin number declarations, and various useful macros.

16687: <p>I am writing my own library for using with my Arduino. In my code, if I set a pointer I have declared to <code>NULL</code>, such as</p>

<pre><code>int *ptr=NULL;
</code></pre>

<p>I get the error</p>

<pre><code>error: ‘NULL’ was not declared in this scope
</code></pre>

<p>I need to initialize it to <code>NULL</code> as I am using pointers to implement a list.</p>

<p>If I use <code>NULL</code> 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.</p>

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

<p>Thank you.</p>
 4143: <p>You should make sure your header includes the <a href="http://pubs.opengroup.org/onlinepubs/7908799/xsh/stddef.h.html" rel="nofollow noreferrer"><code>stddef.h</code></a> header, which holds all these standard definitions (hence its name):</p>

<pre><code>#include &lt;stddef.h&gt;
</code></pre>
 10794: <blockquote>
  <p>I am writing my own library for using with my Arduino.</p>
</blockquote>

<p>You should really include Arduino.h, i.e.</p>

<pre><code>#include &lt;Arduino.h&gt;
</code></pre>

<p>Not only will that define <code>NULL</code> for you, but you also get the other standard Arduino functions like <code>digitalRead</code>, pin number declarations, and various useful macros.</p>
