Jump to content

Recommended Posts

  • Active+ Member

I think it is a regulation that C++11 and above users should implement because it is more compatible with modern and current language standards and safer in terms of code functionality.

NULL most of the time represents the int type (0) in the pointer type and can sometimes conflict with other data types and cause incorrect checks. (When this happens, you will not get any error, and you will not even notice it. However, the code will not work as it should.)

nullptr directly represents the pointer.

Example scenario:
Let's say we have two functions with the same name but different types:

void TestFunc(int arg) // a function that expects an integer.
void TestFunc(int * arg) // a function that expects a pointer.

And suppose we make a call like this from a different location:

test->TestFunc(NULL); // It is unclear which `TestFunc` function will be processed here.

Since NULL data can be interpreted as an int, it can cause confusion and the compiler may not be able to decide which function to call.

 

Therefore, according to this scenario, the correct call form should be as follows:

test->TestFunc(nullptr);

In this case, the compiler will process the TestFunc function that expects a pointer. Accordingly, it is a more correct and safe approach to free pointers as NULL, nullptr, in src codes.

Here you may ask: "So how can we send NULL data to a function that expects an integer?"

To do this, you need to send 0 instead of sending NULL (taking into account the scenario above). That is: test->TestFunc(0);
It is important to consider the arguments and types that the functions expect.

 

Let's continue;

In client source codes, the SAFE_DELETE call resets the pointers to NULL. Because these codes were written with old language standards. They were written correctly according to the conditions of that time. However, it would be better to edit this in today's c++11 and above usage.

Let me explain briefly:

This is the hidden content, please

Now you can reset pointers to nullptr with SAFE_DELETE in the client src. The same operation can be done manually without calling SAFE_DELETE, but here I just show an update to the SAFE_DELETE function that does the same job in a more practical way.

Additionally: this operation is not limited to the client src. You need to consider the same logic on the server side.

"I use Google Translate. Sorry for my bad English."

  • Metin2 Dev 34
  • Good 3
  • Love 11
Link to comment
https://metin2.dev/topic/33142-optional-convert-null-pointers-to-nullptr/
Share on other sites

Don't use any images from : imgur, turkmmop, freakgamers, inforge, hizliresim... Or your content will be deleted without notice...
Use : https://metin2.download/media/add/

Please use https://metin2.download/ when uploading files smaller than 100MB, otherwise the approval will take longer due to manual upload.

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
×
×
  • Create New...

Important Information

Terms of Use / Privacy Policy / Guidelines / We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.