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 866713
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T09:51:16+00:00 2026-05-15T09:51:16+00:00

What you can’t do in C (C99 standard) that you can do in Objective-C?

  • 0

What you can’t do in C (C99 standard) that you can do in Objective-C? (with code example if you please)

  • 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-05-15T09:51:16+00:00Added an answer on May 15, 2026 at 9:51 am

    I’m going to be a little bit presumptuous and disagree with everyone else. While it’s technically true that anything possible in one language is possible in another (where “possible” means “computable”), they differ in what you can express naturally and easily. The computer might be doing the same thing in response to the code you write in C, but you are writing radically different code to make it do those things.

    As others have said, Objective-C provides a full runtime library written in C that will allow you to create Objective-C data structures and call C functions, but the code to do it will be very verbose, fairly roundabout and completely imperative. In Objective-C, the code is more declarative, more concise and far more readable.

    In general, trying to write Objective-C things in C will only make your code worse than it would be using either language idiomatically. For example, here is a simple program written in Objective-C:

    @interface NumberAdder : NSObject {
        int storedValue;
    }
    
    - (id)initWithStoredValue:(int)value;
    - (int)resultOfAddingStoredValue:(int)numberToAdd;
    @end
    
    @implementation NumberAdder
    - (int)resultOfAddingStoredValue:(int)numberToAdd {
        return numberToAdd + storedValue;
    }
    
    - (id)initWithStoredValue:(int)value {
        if (!(self = [super init])) return nil;
        storedValue = value;
        return self;
    }
    @end
    
    int main() {
        id adder = [[NumberAdder alloc] initWithStoredValue:4];
        int result = [adder resultOfAddingStoredValue:3];
        printf("It is %d\n", result);
        return 0;
    }
    

    And here is the same thing written in C with the Objective-C runtime (not tested, but should be roughly correct):

    int returnPlusStoredValueImp(id self, SEL _cmd, int arg) {
        int *storedValue = nil;
        object_getInstanceVariable(self, "storedValue", &storedValue)
        return arg + *storedValue;
    }
    
    id numberAdderInit(id self, SEL _cmd, int valueToStore) {
        objc_super superInfo = {self, objc_lookupClass("NSObject")};
        self = objc_msgSendSuper(super_info, sel_getName("init"));
        if (!self) return nil;
        object_setInstanceVariable(self, "storedValue", &valueToStore);
        return self;
    }
    
    void createNumberAdderClass() __attribute(constructor)__ {
        Class NumberAdder = objc_allocateClassPair(objc_lookupClass("NSObject"), "NumberAdder", 0);
        if (!NumberAdder) return;
        class_addIvar(NumberAdder, "storedValue", sizeof(int), 4, "i"); // I'm actually not sure if the fourth argument is correct, so it's probably wrong, but just take that as a sign of how much this way of coding sucks
        objc_registerClassPair(NumberAdder);
        SEL nameOfPlusStoredValue = sel_registerName("resultOfAddingStoredValue:");
        SEL nameOfInit = sel_registerName("initWithStoredValue:");
        class_addMethod(NumberAdder, nameOfPlusStoredValue, returnPlusStoredValueImp, "i@:i");
        class_addMethod(NumberAdder, nameOfInit, numberAdderInit, "@@:i");
    }
    
    int main() {
        id adder = objc_msgSend(objc_lookupClass("NumberAdder"), sel_getName"alloc");
        adder = objc_msgSend(adder, sel_getName("initWithStoredValue:"), 4);
        int result = (int)objc_msgSend(adder, sel_getName("resultOfAddingStoredValue:"), 3);
        printf("It is %d\n", result);
        return 0;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can somebody point me to a resource that explains how to go about having
Can a LINQ enabled app run on a machine that only has the .NET
Can anyone (maybe an XSL-fan?) help me find any advantages with handling presentation of
Can you cast a List<int> to List<string> somehow? I know I could loop through
can you recommend some good ASP.NET tutorials or a good book? Should I jump
Can anyone tell me how I can display a status message like 12 seconds
Can you tell me what is the difference between abstraction and information hiding in
Can I get a 'when to use' for these and others? <% %> <%#
Can anyone recommend a good library for generating an audio file, such as mp3,
Can you suggest some good MVC framework for perl -- one I am aware

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.