OK, I have some C++ code in a header that is declared like this:
void StreamOut(FxStream *stream,const FxChar *name = nil);
and I get: error:
'nil' was not declared in this scope
nil is a pascal thing, correct?
Should I be using NULL?
I thought they were both the same or at least Zero, no?
Nil means the same as zero. It is usually used to say what the score is in sports such as rugby or football.
Let's start out with “Nil” since it's the most common and easy-to-understand way of representing nothingness in Ruby. In terms of what it means, Nil is exactly the same thing as null in other languages.
Swift's nil is not the same as nil in Objective-C. In Objective-C, nil is a pointer to a non-existent object. In Swift, nil is not a pointer—it is the absence of a value of a certain type. Optionals of any type can be set to nil , not just object types.
In C++ you need to use NULL
, 0, or in some brand new compilers nullptr. The use of NULL
vs. 0 can be a bit of a debate in some circles but IMHO, NULL
is the more popular use over 0.
nil
does not exist in standard C++. Use NULL
instead.
Yes. It's NULL
in C
and C++
, while it's nil
in Objective-C.
Each language has its own identifier for no object. In C
the standard library, NULL
is a typedef of ((void *)0)
. In C++
the standard library, NULL
is a typedef of 0
or 0L
.
However IMHO, you should never use 0 in place of NULL
, as it helps the readability of the code, just like having constant variables in your code: without using NULL, the value 0 is used for null pointers as well as base index value in loops as well as counts/sizes for empty lists, it makes it harder to know which one is which. Also, it's easier to grep
for and such.
0 is the recommended and common style for C++
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With