1. ABOUT NULL IN C
First, I analize what is NULL
in C.
In the standard C99 document we can read, subsectiom 6.3.2.3:
An integer constant expression with the value 0, or such an expression
cast to type void *, is called a null pointer constant.
This defines the null pointer constant.
In every implementation the macro NULL
has to be defined as the null pointer constant.
The macro NULL is defined in (and other headers) as a null pointer constant;
This means that there are only two possibilities to #define
the macro NULL
: 0
or (void*)0
.
The null constant expression has two forms, as we see, but is not necessarilly considered a null pointer.
A conversion to a pointer type of the null pointer constant will bring a null pointer of that type.
The form (void*)0
is per se a null pointer of type void*
.
Any two null pointers compare equal.
The equality operators are ==
and !=
and they allow to compare arithmetic values, as much as pointer values, by following precise rules that I don't copy here. However, I will cite this:
[For equality operators is allowed that] one operand is a pointer and
the other is a null pointer constant.
So, every pointer can be compared against NULL
to check equality.
(Observe that not only pointer to objects are allowed, but pointer to functions also can be compared against NULL
).
If one operand is a pointer and the other is a null pointer constant,
the null pointer constant is converted to the type of the pointer.
This describes how the comparison against NULL
is performed, just in case.
Two pointers compare equal if [...] both are null pointers [...]
I cannot find the right place in the standard where a null pointer of some type, when compared against the null pointer constant, NULL
, gives true. But, anyway, it is clearly intended that this is the expected behaviour.
We can conclude that, althoug every null pointer compared against 0
gives true, the 0
is not a null pointer, but an integer constant. The "real" null pointer value is not represented in any explicit way by the syntax of C, but only in indirect form.
2. WHAT TO DO IN LUA
Well, I don't know Lua, however because of you, I was looking around. There is some relation between Lua and C.
C has not a reserved word in the spirit of nil
to represent null values.
The constant 0 is always an integer, not a pointer, but C compares it true against pointers having null value.
The NULL
macro sometimes is defined as (void*)0
, which is a pointer, but sometimes could be defined as merely 0
, which again is an integer.
Since NULL
is a macro, is not what really matters.
So, I think that none of the options you are thinking reflects what is happening in C.
However, in general, it is used NULL
to designate the null pointer in C.
I saw C functions in Lua, called in some special way.
On the other hand, I infere from your question that some kind of .NULL
thing can be invoked.
3. THE ANSWER
My opinion is that your choice has to be NULL
.
Since you are planning to use that function to check null pointers in C, take in account that in C, the functions that return pointers also can return the null pointer, which, in turn, can be passed as an argument to another functions.
If your functions are expected to return also non-null values and/or to cooperate with another functions related to C pointers, the value NULL
will have to be available.
This would be my choice.
Anyway, I apologize because I am guessing here, since I don't have knowledge about Lua.