# Use of NULL vs nullptr in UE4 C++

**URL:** <https://forums.unrealengine.com/t/use-of-null-vs-nullptr-in-ue4-c/275136>\
**Category:** C++\
**Tags:** unreal-engine, feedback, CPP, question\
**Created:** [March 11, 2014, 1:56am UTC](https://forums.unrealengine.com/t/use-of-null-vs-nullptr-in-ue4-c/275136 "2014-03-11T01:56:01Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![ue4-archive](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@ue4-archive](https://forums.unrealengine.com/u/ue4-archive)\
**Post date:** [March 11, 2014, 1:56am UTC](https://forums.unrealengine.com/t/use-of-null-vs-nullptr-in-ue4-c/275136/1 "2014-03-11T01:56:01Z")

</div>

Dear Friends at Epic,

Expert coder Neil Griffth recently wrote this:

> “You should really try to avoid using  
> NULL if possible and instead use  
> nullptr. It’s a lot safer if only  
> because you’re not checking against a  
> number (zero) - and it’s part of the  
> C++ language as of C++11 (which is  
> required by Rocket in any case!).”

#My Question

I was wondering if NULL in UE4 C++ still uses the actual macro, **or if Epic has done this definition somewhere** :

```
#define NULL nullptr

```

* * *

#Summary

Anyone with any comments on NULL vs nullptr, feel free to post.

I am not taking a stance on this, I am asking for more info 🙂

Though I do want to say, **Thanks Neil for bringing this to my attention**!

Rama

---

<div class="post-metadata">

**Author:** ![ue4-archive](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@ue4-archive](https://forums.unrealengine.com/u/ue4-archive)\
**Post date:** [March 11, 2014, 1:56am UTC](https://forums.unrealengine.com/t/use-of-null-vs-nullptr-in-ue4-c/275136/2 "2014-03-11T01:56:02Z")

</div>

> Expert coder Neil Griffth recently  
> wrote this:

Yep, he truly is … lucky us 🙂

---

<div class="post-metadata">

**Author:** ![ue4-archive](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@ue4-archive](https://forums.unrealengine.com/u/ue4-archive)\
**Post date:** [March 11, 2014, 1:56am UTC](https://forums.unrealengine.com/t/use-of-null-vs-nullptr-in-ue4-c/275136/3 "2014-03-11T01:56:02Z")

</div>

hee hee! 🙂

---

<div class="post-metadata">

**Author:** ![ue4-archive](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@ue4-archive](https://forums.unrealengine.com/u/ue4-archive)\
**Post date:** [March 11, 2014, 1:56am UTC](https://forums.unrealengine.com/t/use-of-null-vs-nullptr-in-ue4-c/275136/4 "2014-03-11T01:56:03Z")

</div>

To answer your question, I think NULL is a Microsoft thing; IIRC it’s defined in Windows.h, which is probably getting included somewhere along the line.

I doubt it’s #defined anywhere. It’s part of C++ now.

But yes, nullptr is most definitely preferred IMO 🙂

---

<div class="post-metadata">

**Author:** ![ue4-archive](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@ue4-archive](https://forums.unrealengine.com/u/ue4-archive)\
**Post date:** [March 11, 2014, 1:56am UTC](https://forums.unrealengine.com/t/use-of-null-vs-nullptr-in-ue4-c/275136/5 "2014-03-11T01:56:03Z")

</div>

neat!

The .h files of UE4 mostly use NULL, I found about 30 references in the .h to nullptr

I’m just curious if Epic has made them internally the same by

```
#define NULL nullptr 

```

or not

---

<div class="post-metadata">

**Author:** ![ue4-archive](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@ue4-archive](https://forums.unrealengine.com/u/ue4-archive)\
**Post date:** [March 11, 2014, 1:56am UTC](https://forums.unrealengine.com/t/use-of-null-vs-nullptr-in-ue4-c/275136/6 "2014-03-11T01:56:03Z")

</div>

It’s unlikely that they did that - if they did that then it could break code for people who are using NULL as a value. 🙂

---

<div class="post-metadata">

**Author:** ![ue4-archive](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@ue4-archive](https://forums.unrealengine.com/u/ue4-archive)\
**Post date:** [March 11, 2014, 1:56am UTC](https://forums.unrealengine.com/t/use-of-null-vs-nullptr-in-ue4-c/275136/7 "2014-03-11T01:56:04Z")

</div>

Well, thanks again for shedding light on this subject Neil!

#❤

---

<div class="post-metadata">

**Author:** ![ue4-archive](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@ue4-archive](https://forums.unrealengine.com/u/ue4-archive)\
**Post date:** [March 11, 2014, 1:56am UTC](https://forums.unrealengine.com/t/use-of-null-vs-nullptr-in-ue4-c/275136/8 "2014-03-11T01:56:04Z")

</div>

Just to clarify, you can check with:

int value1 = NULL;  
int value2 = nullptr;

The first compiles, but not the second, meaning NULL is still defined to 0.

---

<div class="post-metadata">

**Author:** ![ue4-archive](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@ue4-archive](https://forums.unrealengine.com/u/ue4-archive)\
**Post date:** [March 11, 2014, 1:56am UTC](https://forums.unrealengine.com/t/use-of-null-vs-nullptr-in-ue4-c/275136/9 "2014-03-11T01:56:04Z")

</div>

oooh great insight Andrew!

**Thanks Andrew!**

That fully answers this thread 🙂

Thanks everyone, for the info!

#❤

Rama

---

<div class="post-metadata">

**Author:** ![anon67567687](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anon67567687](https://forums.unrealengine.com/u/anon67567687)\
**Post date:** [November 9, 2018, 9:02pm UTC](https://forums.unrealengine.com/t/use-of-null-vs-nullptr-in-ue4-c/275136/10 "2018-11-09T21:02:58Z")

</div>

Found the answer on the coding standard page :

> **[Coding Standard](https://docs.unrealengine.com/5.3/en-US/epic-cplusplus-coding-standard-for-unreal-engine/)**
>
> Write maintainable code by adhering to established standards and best practices.

> nullptr should be used instead of the  
> C-style NULL macro in all cases. One  
> exception to this is that nullptr in  
> C++/CX builds (such as for Xbox One)  
> is actually the managed null reference  
> type. It is mostly compatible with  
> nullptr from native C++ except in its  
> type and some template instantiation  
> contexts, and so you should use the  
> TYPE\_OF\_NULLPTR macro instead of the  
> more usual decltype(nullptr) for  
> compatibility.

---

<div class="post-metadata">

**Author:** ![MBybee](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@MBybee](https://forums.unrealengine.com/u/MBybee)\
**Post date:** [September 13, 2020, 12:16am UTC](https://forums.unrealengine.com/t/use-of-null-vs-nullptr-in-ue4-c/275136/11 "2020-09-13T00:16:58Z")

</div>

This is an old thread, but I thought I’d mention that as of 4.25.3, the Third Person Template from Epic still uses !=NULL repeatedly in the character CPP  
If that’s not a good practice, they should _probably_ update their code samples to keep people from misunderstanding it.

---

<div class="post-metadata">

**Author:** ![Mynkela](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Mynkela](https://forums.unrealengine.com/u/Mynkela)\
**Post date:** [August 14, 2021, 4:02pm UTC](https://forums.unrealengine.com/t/use-of-null-vs-nullptr-in-ue4-c/275136/12 "2021-08-14T16:02:35Z")

</div>

_Example:_

```
class AMyDefaultClass* theDefaultClass;

```

\*\*\*\*//**the class was exist & IsValid(), So class is not NULL**

```
if(theDefaultClass != NULL) UE_LOG(LogTemp, Warning, TEXT("AMyDefaultClass is not NULL"));

```

**//the class IsValid() but you not able to use class data(variable, function(), etc) with public otherwise crash editor, So class was nullptr**

```
if(theDefaultClass == nullptr) UE_LOG(LogTemp, Warning, TEXT("AMyDefaultClass was nullptr"));
```
