check pointer by "!"

 

Is this

if(pointerObj == NULL || CheckPointer(pointerObj)==POINTER_INVALID){..}

the same as this:

if(!pointerObj){..}

As it is said in https://www.mql5.com/en/docs/basis/types/object_pointers;

To quickly validate the pointer, you can also use operator "!" (LNOT) which checks it via an implicit call of the CheckPointer function.

Documentation on MQL5: Language Basics / Data Types / Object Pointers
Documentation on MQL5: Language Basics / Data Types / Object Pointers
  • www.mql5.com
MQL5 enables the dynamic creation of complex type objects. This is done by using the ‘new’ operator which returns a descriptor of the created...
 
harryma23:

Is this

the same as this:

As it is said in https://www.mql5.com/en/docs/basis/types/object_pointers;

To quickly validate the pointer, you can also use operator "!" (LNOT) which checks it via an implicit call of the CheckPointer function.

If you are aware of the value in pointer variable, a check against NULL is sufficient.

CheckPointer will check if the object actually exists, even if the value in pointer is not NULL.
 

>CheckPointer will check if the object actually exists, even if the value in pointer is not NULL.

I know, the question was:

Is 
if(pointerObj == NULL || CheckPointer(pointerObj)==POINTER_INVALID){..}

the same as

if(!pointerObj){..}

Yes or no?

According to the documentation, "This is checked by an implicit call to the CheckPointer function." I don't know what kind of pointer check is performed (I suspect POINTER_INVALID) AND whether the pointer is also checked for NULL behind the scene when doing if(!pointerObj). That's the questions, nothing else.

Documentation on MQL5: Common Functions / CheckPointer
Documentation on MQL5: Common Functions / CheckPointer
  • www.mql5.com
The function returns the type of the object pointer . Parameters anyobject [in]  Object pointer. Return value Returns a value from the...
 
harryma23 #:

>CheckPointer will check if the object actually exists, even if the value in pointer is not NULL.

I know, the question was:

Is 

the same as

Yes or no?

According to the documentation, "This is checked by an implicit call to the CheckPointer function." I don't know what kind of pointer check is performed (I suspect POINTER_INVALID) AND whether the pointer is also checked for NULL behind the scene when doing if(!pointerObj). That's the questions, nothing else.

Test it.
 
harryma23 #:

>CheckPointer will check if the object actually exists, even if the value in pointer is not NULL.

I know, the question was:

Is 

the same as

Yes or no?

According to the documentation, "This is checked by an implicit call to the CheckPointer function." I don't know what kind of pointer check is performed (I suspect POINTER_INVALID) AND whether the pointer is also checked for NULL behind the scene when doing if(!pointerObj). That's the questions, nothing else.


As you can see by your own code, its not the same. The outcome is achieving the same.

Your first if statement uses short-circuit in case pointer == NULL, else it will call CheckPointer.

Your second if-statement is a single, implicit call to CheckPointer, validating the pointer. It will be true if CheckPointer returns POINTER_INVALID.

BTW, that's what I stated implicitly in my last post.
 
Dominik Egert #:
Your second if-statement is a single, implicit call to CheckPointer, validating the pointer. It will be false if CheckPointer returns POINTER_INVALID.
Will 
if(!pointerObj){..}

also return false if pointerObj is NULL

Otherwise, only the following statement

f(pointerObj == NULL || !pointerObj){..}

is the same as 

if(pointerObj == NULL || CheckPointer(pointerObj)==POINTER_INVALID){..}

Am I right?

 
harryma23 #:
Will 

also return false if pointerObj is NULL

Otherwise, only the following statement

is the same as 

Am I right?

The question is valid, but still answered already. 
 
Dominik Egert #:
The question is valid, but still answered already. 

I know my question is valid. And your answers aren't!

I can't see a simple yes or no from any of your answers —my questions are very direct and crystal-clear, aren't they? I know you maybe want to help—but please don't answer if you can't give clear, direct answers!

Look at your answers; is there a "yes" or "no"? Why don't you just answer "yes" or "no" instead of giving an indirect answer with a lot of room for interpretation and wasting my time with your trivial, unhelpful answers. The summary of your answers:

You said:

"Your second if-statement is a single, implicit call to CheckPointer, validating the pointer. It will be false if CheckPointer returns POINTER_INVALID."

I know! That's not the question! And will it be also false if the pointer is NULL.That's the interesting part which you do not say.

You said:

"CheckPointer will check if the object actually exists, even if the value in pointer is not NULL."

Such a contradictory answer! Even if the value in the pointer is not NULL? Again, especially for you:

CheckPointer checks whether the object actually exists, even if the value in the pointer is NULL." That would be a straightforward answer.

But you're causing a lot of confusion on this topic—even though it's a clear yes-or-no question. So please stop answering like that!



Again – for everyone else who knows how to answer a simple yes or no question correctly

Is this

if(pointerObj == NULL || CheckPointer(pointerObj)==POINTER_INVALID){..}

the same as

if(!pointerObj){..}

Yes or no

 
harryma23 #:

I know my question is valid. And your answers aren't!

I can't see a simple yes or no from any of your answers —my questions are very direct and crystal-clear, aren't they? I know you maybe want to help—but please don't answer if you can't give clear, direct answers!

Look at your answers; is there a "yes" or "no"? Why don't you just answer "yes" or "no" instead of giving an indirect answer with a lot of room for interpretation and wasting my time with your trivial, unhelpful answers.


Again – for everyone else who knows how to answer a simple yes or no question correctly

Is this

the same as

Yes or no?

Mister, watch your tone.

When I do not answer more directly, its because I want you to turn on your brain.

But to answer and spoonfeed your idiocracy: No!

EDIT:

What is so hard to understand about an implicit function call?

When checking via "!" You are checking by CheckPointer() == POINTER_INVALID

How stubborn do you need to be to not understand your own question?
 
Dominik Egert #:
Mister, watch your tone.

When I do not answer more directly, its because I want you to turn on your brain.

But to answer and spoonfeed your idiocracy: No!

EDIT:

What is so hard to understand about an implicit function call?

When checking via "!" You are checking by CheckPointer() == POINTER_INVALID

How stubborn do you need to be to not understand your own question?

No ? Not so easy.

Maybe. It depends to what is applying the "same" ? 

Strictly speaking they are not the same as they are different.

Semantically they are not the same as we don't know how '!' is implemented with a pointer. Maybe !ptr is replaced by ptr== NULL || CheckPointer(ptr)==POINTER_INVALID by the compiler ? 

The final result is the same though. No ?

 
Dominik Egert #:
When checking via "!" You are checking by CheckPointer() == POINTER_INVALID
Unfortunately, I can't see the source code of the MQL compiler.

I don't know if the syntactical simplification if(!pointer) also checks for NULL. But apparently not.

Nevertheless, A little tip: 

Please don't answer such simple yes-or-no questions with contradictions or uncertainties – that is neither polite nor helpful. And if you don't "want" to answer such easy questions directly, then don't answer - that's not correct!