NULL is not a built-in constant in the C or C++ languages. In fact, in C++ it's more or less obsolete, just use a plain literal 0 instead, the compiler will do the right thing depending on the context.

In newer C++ (C++11 and higher), use nullptr (as pointed out in a comment, thanks).

Otherwise, add

#include <stddef.h>

to get the NULL definition.

Answer from unwind on Stack Overflow
🌐
PlatformIO Community
community.platformio.org › t › null-undeclared-first-use-in-this-function › 21417
'NULL' undeclared (first use in this function) - PlatformIO Community
May 13, 2021 - I try to get rid of 900 lines of code in a main.cpp file. For that I tried to set up some kind of project directory structure. The first attempt is in: But when creating xTaskCreatePinnedToCore() in this code I get an error: ‘NULL’ undeclared (first use in this function) #include #include #include // #include void createAllTasks() { // All xTaskCreate… goes here and utilize the macros created // in taskConfig.h // Be...
🌐
TechOverflow
techoverflow.net › 2019 › 06 › 20 › how-to-fix-c-error-null-undeclared
How to fix C error 'NULL undeclared' | TechOverflow
April 1, 2026 - main.c: In function ‘main’: main.c:3:17: error: ‘NULL’ undeclared (first use in this function) void* ptr = NULL; ^~~~ main.c:3:17: note: each undeclared identifier is reported only once for each function it appears in
Discussions

c - NUL undeclared- first use in this function - Stack Overflow
From the web I understand that C contains NUL keyword. But while compiling I get an error NUL undeclared first use in this function' My code fragment: for (;;) { char ch = (*pzDest = *pz... More on stackoverflow.com
🌐 stackoverflow.com
October 24, 2016
C Errors (Beginner) - Stack Overflow
#include main(void) { ... file) != null) { fputs ( line, stdout ); } fclose ( file ); } } This is my code. im trying to read a file, and output the content. but this gives me error codes · main.c: In function 'main': main.c:4: error: 'file' undeclared (first use in this ... More on stackoverflow.com
🌐 stackoverflow.com
March 4, 2009
'NULL' undeclared (first use in this function) using android ndk - Stack Overflow
I am working on android-ndk in which i try to pass string from my C code to my java and then in activity. My codes are given below but i am getting the following errors. Please help me out here #i... More on stackoverflow.com
🌐 stackoverflow.com
Why am I getting undeclared (first use in this function)
because fName is not the same as fname. Case sensitive. More on reddit.com
🌐 r/learnprogramming
5
3
April 8, 2015
🌐
Cprogramming
cboard.cprogramming.com › cplusplus-programming › 103806-null-undeclared-first-use-function.html
'NULL' undeclared (first use this function)
June 3, 2008 - I think you are misunderstanding the error message: First use in this function means that it is only recorded as undeclared ONCE, not every time it's being used (because it's usually only ONE mistake to not declare something - and the compiler telling you that 35 times because that's how many ...
🌐
Gentoo
bugs.gentoo.org › 889557
889557 – sys-apps/isapnptools-1.27 - pnp-select.c: error: NULL undeclared (first use in this function)
January 3, 2023 - Gentoo's Bugzilla – Bug 889557 sys-apps/isapnptools-1.27 - pnp-select.c: error: NULL undeclared (first use in this function) Last modified: 2025-10-05 20:03:38 UTC node [vulture]
🌐
GitHub
github.com › miraclelinux › meta-debian-extended › pull › 91
mesa-native: Fix NULL undeclared by cheat-sc · Pull Request #91 · miraclelinux/meta-debian-extended
August 9, 2019 - When build qemu-system-native package with gl enable, build errors occurred like follows: ../../../mesa-18.3.6/src/egl/main/egldevice.h:54:13: error: ‘NULL’ undeclared (first use in this function) dev = NULL; ^~~~ This commits fixes the error.
Author   miraclelinux
Find elsewhere
🌐
GeeksforGeeks
geeksforgeeks.org › c++ › null-undeclared-error-in-c-c-and-how-to-resolve-it
NULL undeclared error in C/C++ and how to resolve it - GeeksforGeeks
July 15, 2025 - #define NULL 0: Using #define NULL 0 line in our program, we can solve the NULL undeclared error. Below code shows its implementation: ... In newer C++(C++11 and higher):: nullptr is a built-in constant, so we can use it instead of using NULL.
🌐
Narkive
bug-gnulib.gnu.narkive.com › Y0SHyW6Y › select-c-496-error-null-undeclared
select.c:496: error: `NULL' undeclared - bug-gnulib@gnu.org
Permalink I got this error on a IRIX 6.5 system: checking for sys/select.h... yes checking whether <sys/select.h> is self-contained... no checking whether pselect is declared without a macro... no checking whether select is declared without a macro... no checking whether select supports a 0 argument... no ... CC select.lo select.c: In function `rpl_select': select.c:496: error: `NULL' undeclared (first use in this function) select.c:496: error: (Each undeclared identifier is reported only once select.c:496: error: for each function it appears in.) select.c:500: warning: implicit declaration of function `select' I pushed the patch below.
🌐
Educative
educative.io › answers › what-is-the-null-undeclared-error-in-c-cpp
What is the NULL undeclared error in C/C++?
Executing the above code gives the NULL undeclared error at main.cpp:5:12. This happens because NULL is not a built-in constant in the C or C++ languages.
🌐
YouTube
youtube.com › linuxtarget
undeclared first use in this function - YouTube
How to fix c/c++ compiler error: undeclared first use in this function ?#syntax #c #howto #clanguage #cppprogramming #error #compiler #codeblocks
Published   August 21, 2022
Views   4K
🌐
Reddit
reddit.com › r/learnprogramming › why am i getting undeclared (first use in this function)
r/learnprogramming on Reddit: Why am I getting undeclared (first use in this function)
April 8, 2015 -
#include <stdio.h>
#include <stdlib.h>
#include <string.h>



struct info 
{
  char *firstName;
  char *lastName;
  int PUID;
  int age;
};

struct node
{
struct info student;
struct node *next;
};


struct node *root = NULL;
struct node *curr = NULL;

void create_list_node( char fName[30], char lName[30], int id, int ages);
int main()
{

return 0;
}

/*
void create_list_no_nodes()
{
root = (struct node*)malloc(sizeof(struct node));
root-> next = 0;
}

*/

void create_list_node( char fName[30], char lName[30], int id, int ages)
{
  free(root);
  root = (struct node *) malloc(sizeof(struct node));


  root->student.firstName = fname;
  root->student.lastName = lname;
  root->student.PUID = id;
  root->student.age = ages;
  root->next = NULL; 

here is the error:

Lab5_main.c: In function ‘create_list_node’:
Lab5_main.c:54:29: error: ‘fname’ undeclared (first use in this function)
   root->student.firstName = fname;
                         ^
Lab5_main.c:54:29: note: each undeclared identifier is reported only once for each function it appears in
Lab5_main.c:55:28: error: ‘lname’ undeclared (first use in this function)
   root->student.lastName = lname;
                        ^
🌐
Depot Games
allegro.cc › forums › thread › 332697
'NULL' undeclared...
Allegro.cc Forums » Programming Questions » 'NULL' undeclared... ... Site Index | Search | News | Forums | Wiki | Online Users | View Source Copyright ©1999-2025, by Matthew Leverton You are visitor #122,436,366 since January 1999. This page has been viewed 664 times since March 2002.
🌐
Parasoft Forums
forums.parasoft.com › insure++
Getting undeclared error for the variable which is already declared. — Parasoft Forums
December 14, 2020 - It seems you have declared xyz inside the memset function block, making it out of scope for the memcpy function. To resolve this, move the void* xyz = &num; declaration to the beginning of the ABC function, before the memset and memcpy calls. This way, XYZ will be in scope for both functions, and the compilation error should be resolved.
🌐
Delft Stack
delftstack.com › home › howto › cpp › cpp null undeclared error
NULL Undeclared Error in C++ | Delft Stack
March 11, 2025 - The NULL undeclared error in C++ indicates that the compiler does not recognize the NULL keyword. This can happen for several reasons, including missing standard library headers or misconfigured project settings.
🌐
EmbDev
embdev.net › arm programming with gcc/gnu tools
error: 'NULL' and 'stderr' undeclared - EmbDev.net
June 23, 2017 - EmbDev.net · Contact – Data privacy information – Advertising on EmbDev.net