What is the difference between 0 and NULL? And how are such names as NULL called? What are you looking for like this example?
- oneNULL is fixed - \ #define NULL 0 applications can be fixed in the previous page the compiler, scho de (okrіm text in paws) is required by one deputy to another - sudo97
- 3Ilya, I respect the Ukrainian culture and language, but it’s accepted here, nevertheless, to write in Russian. If you can, write in Russian, respect others, because not everyone on the forum speaks Ukrainian. - skegg
|
2 answers
NULL
is just #define
to 0
. With the release of the new standard it is recommended to use nullptr
.
- and what are you looking for is #define? - nullptr
- fourThere is still any define - you can declare them yourself. - uramer239
|
You can also create your own analogue nullptr:
class null { null() {} void operator&() const; public: template<class T> operator T*() const {return 0;} static null _inst; } const &null=null::_inst; class null null::_inst;
- oneAnd what is the practical value of such structures? Discussions at conferences on the theoretical foundations of the semantics of programming languages and writing dissertations? - avp 2:58 pm
- 3NULL does not always match nullptr. For example, you can write int n = NULL, but you cannot write n = nullptr or, using my null n = null. If there is an overloaded function void func (int x); void func (void * ptr); A person may want to call a variant with void *, passing a null pointer, but if he uses NULL, he will call an int option. nullptr and null will give the expected result. If nullptr is not supported, it is better to use this null. - gammaker
- 2@avp Well, for about the same purpose as normal programmers use static asserts . I, for example, for transferring part of the compliance checks to the compiler, rather than later catching them in runtime. Especially because the working static assert is better than the unknown crashes in the production due to the fact that, for example, the structure was not aligned as you expected. With
nullptr
the same story. - Costantino Rupert - 3@avp Well, I won't argue too much. It's just that the crosses are a generalization over a simple
C
, respectively, in order to get the compatibility of the code base, many things were solved by crutches that will work both there and there. And then for crutches they begin to invent new crutches, so that the language corresponds to some more progressive concepts, such as, * "Oh, strict typing is NULL!" , let's get it started. And since#define NULL
already there, then let's call itnullptr
and include it in the new standard. In short, the standard path for an imperfect language that has evolved over 20 years. - Costantino Rupert - 3@avp I feel, I’m going to step out now too :) - Costantino Rupert
|