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 = *pzSrc);
if (ch == NUL)
break;
if (ch == ':') {
*pzDest = NUL;
break;
}
pzDest++;
pzSrc++;
}
Any idea why I get this error?
There's NULL and then there's NUL.
NULL is defined in stddef.h, is used very widely, and is a reference to a null pointer.
NUL is different - it is the first character in the standard ASCII character set, and more importantly, it is not a standard macro. You may have to define it yourself.
To define NUL, do:
Defining your own NULL value is not standard, and very error prone and that will for sure give you no sleep nights and headaches in the best case.
Issues with the concept of NULL values between C and C++ and within C++ C++98, C++0x, and C++11 is not new, this is why from C++0x onward the nullptr macro has been introduced to avoid issues and harmonise things a bit.
If however you used code that inherits from issue of the legacy NULL burden:
Depending on your configuration, in the order in which your externals and libs are included etc, you might need to ensure that NULL is defined on time.
The easiest way is to include "stddef.h", note that the content of stddef.h may vary a lot depending on your system/linux flavor, this is an example:
Example:
I had the issue trying to use the i2c library to drive i2c buses on a Raspberry-pi. In my case including the i2c lib wasn't enough, I had to create a utils.h file that I include in place of the i2c lib header:
No, that's not standard. Add this at the beginning of your code or just use
0
:I infered you're not looking for
NULL
since you're doingch == NUL
In various texts it is quite frequent to refer to
'\0'
asNUL
.It's
NULL
, notNUL
.EDIT
Did you even read the link you posted? It says very specifically "NULL is not NUL. NUL is not a defined keyword in C++"