Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8723519
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T07:38:56+00:00 2026-06-13T07:38:56+00:00

In C there is a default implementation of equality operator. Go through all the

  • 0

In C there is a default implementation of equality operator. Go through all the member and verify that they satisfy the equality operator. The default is somewhat stupid because if an object contains pointer then the equality operator of the member would be performed on the pointer.

Still, it’s good enough for my purpose.

So does it?

Or are we expected to implement isEqual and the corresponding hash for everytime we create a custom object that may we want to use isequal for.

It seems to me the “default” implementation is to simply compare the pointer of the object and not it’s member. Am I correct here? It’s even worse than C++ standard comparison. That’s what I want to verify.

It seems to me if our class is the immediate children of NSObject then isEqual will simply call it’s parent’s isEqual and that simply compare pointers.

Am I correct here? I am just wanting to make sure of that.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T07:38:58+00:00Added an answer on June 13, 2026 at 7:38 am

    As NSObject provides isEqual:, and all your objects are descendants of NSObject, then the the simple answer is that a default implementation is provided.

    Now you are concerned over the algorithm this default uses, and in a comment write “I wouldn’t be sure simply by testing”. Let’s look at testing, just for fun 😉

    Now isEqual: is a rather fundamental method, if Apple decided to change its semantics the consequences could be significant and not good. So while Apple is free to change how it is implemented provided the semantics remain the same, which means the same objects compare equal after the change as before. Now you’ve mentioned three possible algorithms isEqual: could use:

    1. Pointer comparison – is it the exact same object
    2. Shallow comparison – do the fields of the object have the same value compared directly
    3. Deep comparison – do the non-pointer-valued fields compared directly have the same value, and do the pointer-valued fields compare equal using isEqual:

    These all have different semantics, whichever one Apple has chosen it can’t change without breaking a lot of code. And different semantics means you can test…

    Coding as I type, errors expected! Only important bits included:

    @implementation A
    
    - (BOOL) isEqual:(id)other
    {
       NSLog(@"A.isEqual called");
       return self == other; // true iff same object
    }
    
    @end
    
    @interface B
    
    @property (readwrite) int anInteger;
    @property (readwrite) A *anA;
    
    @end
    
    @implementation B
    
    @synthesize anInteger, anA;
    
    @end
    
    // Let's test the algorithm
    
    A *myA = [A new];
    B *bOne = [B new];
    B *bTwo = [B new];
    
    bOne.anInteger = 42;
    bOne.anA = myA;
    
    bTwo.anInteger = 42;
    bTwo.anA = myA;
    
    // What output is produced (all of it!)
    NSLog(@"[bOne isEqual:bTwo] -> %@", [bOne isEqual:bTwo] ? @"Yes" : @"No");
    

    HTH a little.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there a default function in Oracle that allows you to pass the date
Possible Duplicate: Concatenate Two NSDate String values Just confused that is there any default
My teacher told us that there is a default class in Java for binary
My question may duplicate Default implementation for Object.GetHashCode() but I'm asking again because I
Is there a specific design pattern that describes the scenario where a non-abstract default
By default there is a single line separator in uitableview. But I want to
By default there are two appenders in JBoss5.1 - CONSOLE and FILE . Do
Is there a default value for Twitter's newish max_id parameter? I've tried: https://api.twitter.com/1/statuses/user_timeline.json?screen_name=justinbieber&trim_user=true&count=200&max_id=false https://api.twitter.com/1/statuses/user_timeline.json?screen_name=justinbieber&trim_user=true&count=200&max_id=null
Is there any default functionality for arranging JInternalFrames in Java Swing? I would like
Is there a default classpath on Mac OS X 10.6? When I echo $CLASSPATH

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.