View unanswered posts | View active topics It is currently Thu Jul 31, 2014 2:33 am






Reply to topic  [ 4 posts ] 
Is it possible to compare references ? 
Author Message
Moderator
Moderator
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3165
Location: Rotterdam, The Netherlands
Post Re: Is it possible to compare references ?
Hi Miki,

You might be able to do with your own homebrew version of memcmp(). There is currently no native way of doing this, though.

I'll send a mail tot he devs to ask if it is possible to implement this.

- Xander

_________________
| Professional Conduit of Reasonableness
| (Title bestowed upon on the 8th day of November, 2013)
| My Blog: I'd Rather Be Building Robots
| ROBOTC 3rd Party Driver Suite: [Project Page]


Sat Jan 21, 2012 6:58 am
Profile WWW
Moderator
Moderator
User avatar

Joined: Tue Sep 14, 2010 9:19 pm
Posts: 496
Post Re: Is it possible to compare references ?
I don't think that even ANSI C offers intelligent comparison of structs. As Xander said, you should be able to accomplish this by writing a function similar to equalsTo() in Java. Compare the structs member by member:

Code:
bool cmpSFC(S_FIFO_COORD& SFC1, S_FIFO_COORD& SFC2, int pointArrSize){
  for(int i = 0; i< pointArrSize; i++){
    if(!(SFC1.Point[i].x == SFC2.Point[i].x && SFC1.Point[i].y == SFC2.Point[i].y)){
      return false;
    }
  }
  return (SFC1.Max == SFC2.Max) && (SFC1.Nbr == SFC2.Nbr) && (SFC1.Old == SFC2.Old) && (SFC1.New == SFC2.New);
}


I don't know how you plan on determining the size of the Point array, so I just threw in a parameter.

EDIT: Sorry, posted just after the above post and didn't read it carefully.

_________________
sudo rm -rf /


Sat Jan 21, 2012 8:37 am
Profile
Guru
User avatar

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1347
Post Re: Is it possible to compare references ?
I attempted to write code to compare the "reference" passed to a function. This is so that the function knows which instance it is and can do different things accordingly. But it didn't work. If RobotC had pointer support, this is totally straight forward. Like I said, I tried it last year and it did not work. Now that we have 3.05 and it seems it has partial support of pointers, I am wondering if you can do that now. In any case, I get around this problem by adding an "instance ID" in the structure.
Code:
// THIS IS A C ANSI CODE
// THIS IS NOT ROBOTC CODE
typedef struct
{
  int PointID;
  int X;
  int Y;
} COORD;

COORD P1 = {1, 15, 3};
COORD P2 = {2, 40, 6};
COORD P3 = {3, 8, 20};

void fn(S_COORD & pPoint)
{
  if(pPoint.PointID == 1)
  {
     ... // code specific if argument is a pointer on P1
  }
  ... // code non specific
}

void main()
{
  fn(P1); // fn() will execute the non-specific code + the specific code dedicated to P1
  fn(P2); // fn() will execute the non-specific code only
  fn(P3); // fn() will execute the non-specific code only
}


Sun Jan 22, 2012 12:31 am
Profile
Moderator
Moderator
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3165
Location: Rotterdam, The Netherlands
Post Re: Is it possible to compare references ?
Looks like memcmp() has been implemented for the next release :)

You could easily implement a compare function with memcmp() if you have a unique identifier member for each object.

- Xander

_________________
| Professional Conduit of Reasonableness
| (Title bestowed upon on the 8th day of November, 2013)
| My Blog: I'd Rather Be Building Robots
| ROBOTC 3rd Party Driver Suite: [Project Page]


Sun Jan 22, 2012 2:47 am
Profile WWW
Display posts from previous:  Sort by  
Reply to topic   [ 4 posts ] 

Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  



Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.