wierd == operator usage

So I came upon this line I didn't understand
1
2
3
4
5
6
7
8
 DLLIMPORT void lv_EQ_0100(int A, int B, double C, int * err)
      {
		  try
		  {	  			
			cv::Mat * pA=(cv::Mat*)A;
			cv::Mat * pB=(cv::Mat*)B;
			
			*pA=*pB == C;

== means equals to for all I know. I only expect to see this in a form of an 'if' statement so how does this work here?

Something familier stuff:
1
2
3
4
5
6
7
8
DLLIMPORT void lv_GTEQ_0101(int A, int B, int C, int * err)
      {
		  try
		  {	  			
			cv::Mat * pA=(cv::Mat*)A;
			cv::Mat * pB=(cv::Mat*)B;
			cv::Mat * pC=(cv::Mat*)C;
			*pA=*pB>=*pC;

1
2
3
4
5
6
7
8
DLLIMPORT void lv_NOTEQ_0101(int A, int B, int C, int * err)
      {
		  try
		  {	  			
			cv::Mat * pA=(cv::Mat*)A;
			cv::Mat * pB=(cv::Mat*)B;
			cv::Mat * pC=(cv::Mat*)C;
			*pA=*pB != *pC;



As always, thanks in advance
Last edited on
I might be wrong but an example equivalent sample:

1
2
3
4
5
6
7
8
9
10
11
12


	bool result(true);

	int a(8);
	int b(9);

	result = (a == b);
         
        // result is now false

}


== has a higher precedence than =.

So, to me, it's not that much of a weird useage.
Last edited on
This is calculated as *pA = (*pB == C)
result of operator == is bool, which can be converted into int. False concerts to 0 and true to 1.

So this can be read as:
1
2
3
4
if(*pB == C)
    *pA = 1;
else
    *pA = 0;
The *pB is a cv::Mat. There is the realm of overloaded relational operators that the code samples shed no light on. However, it would be uncivil for them to return anything but bool.
Make sense, thanks guys
closed account (1CfG1hU5)
*pA=*pB == C;

C is equal to the pointer pB which is stored in pointer pA

or

pointer pB is equal to C, not assigned to C, pointer pB stored to pointer pA

"=" is the assignment operator

"==" checks for equality

int i = 0; // assign

int x = 0;
int y = 1;

if (x == y)
// then do something, otherwise do not

maybe a statement

if (*pB == C)
*pA = *pB; // if true, assign
Last edited on
closed account (1CfG1hU5)
*pA=*pB>=*pC;

pointer pB is greater than or equal to pointer pC, pointer pB is stored to pointer pA

if (*pB >= *pC)
// statement(s) here for if to execute, braces if more than one
Last edited on
closed account (1CfG1hU5)
*pA=*pB != *pC;

pointer pB is not equal to pointer pC, pointer pB is stored to pointer pA


if (*pB != *pC)
// statement(s) to execute here, more than one statement uses braces
Last edited on
jt1 wrote:
*pA=*pB == C;

C is equal to the pointer pB which is stored in pointer pA

or

pointer pB is equal to C, not assigned to C, pointer pB stored to pointer pA

Incorrect.


jt1 wrote:
*pA=*pB>=*pC;

pointer pB is greater than or equal to pointer pC, pointer pB is stored to pointer pA

Incorrect.


jt1 wrote:
*pA=*pB != *pC;

pointer pB is not equal to pointer pC, pointer pB is stored to pointer pA

Incorrect.
cv::Mat * pB;
(* pA) = ( (* pB) == C );

pB is a pointer.
*pB is the object pointed to by pointer pB.
The type of *pB is cv::Mat.

What jt1 writes is therefore indeed incorrect.
Topic archived. No new replies allowed.