Can nullptr be emulated in gcc?

前端 未结 5 1992
清歌不尽
清歌不尽 2020-12-02 11:09

I saw that nullptr was implemented in Visual Studio 2010. I like the concept and want to start using it as soon as possible; however GCC does not support it yet

5条回答
  •  北海茫月
    2020-12-02 11:39

    Also, gcc (actually g++) has had an extension __null for years. This was counted as industry implementation experience when the nullptr proposal came out.

    The __null extension can detect special cases and warn about them such as accidentally passing NULL to a bool parameter, when it was intended to be passed to a pointer parameter (changes made to a function, forgot to adapt the call side).

    Of course this isn't portable. The template solution above is portable.

提交回复
热议问题