What is the purpose of null?

后端 未结 25 2579
别那么骄傲
别那么骄傲 2020-12-07 22:24

I am in a compilers class and we are tasked with creating our own language, from scratch. Currently our dilemma is whether to include a \'null\' type or not. What purpose do

25条回答
  •  南笙
    南笙 (楼主)
    2020-12-07 23:01

    In C NULL was (void*(0)), so it was a type with value(?). But that didn't work with C++ templates so C++ made NULL 0, it dropped the type and became a pure value.

    However it was found that having a specific NULL type would be better so they (the C++ committee) decided that NULL will once again become a type (in C++0x).

    Also almost every language besides C++ has NULL as a type, or an equivalent unique value not the same as 0 (it might be equal to it or not, but its not the same value).

    So now even C++ will use NULL as a type, basically closing the discussions on the matter, since now everyone (almost) will have a NULL type

    Edit: Thinking about it Haskell's maybe is another solution to NULL types, but its not as easy to grasp or implement.

提交回复
热议问题