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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T21:40:44+00:00 2026-05-27T21:40:44+00:00

I have a C function in MyClass and can call it from inside that

  • 0

I have a C function in MyClass and can call it from inside that class. Is it possible to send an instance of MyClass the C function as a message?

To explain fully, at the moment

MyClass *obj = [[MyClass alloc] init];
[obj myCFunction];

Gives the compiler error: “Receiver type ‘MyClass’ for instance message does not declare a method with selector ‘myCFunction'”. myCFunction is declared within MyClass.h @interface and the full code is before @implementation in MyClass.m and works fine if called from within the @implementation of MyClass.m. Is it therefore that C functions are private, and can I make it public so I can send it as a message to an instance of MyClass?

I am trying to write unit tests which test each stage of some calculations so simply creating an objective c method to call the c function doesn’t seem like an efficient solution.

Any help would be much appreciated

  • 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-27T21:40:44+00:00Added an answer on May 27, 2026 at 9:40 pm

    Nope. Sending messages is an Objective-C construct, so you must have a method defined for an object (or class) to send a message. You have two choices: write an instance method that calls the C function, or pass the C function the object it should use.

    If the C function is declared in your header file it is public to all files that include that header file. Therefore you can call it from your testing code, it just doesn’t know what object you’re referring to if you are referencing data declared in your .m file. You should make explicit which object you are referring to in the C function by passing it a reference to that object. Within the class implementation the C function would be called with myCFunction(self). Then access any of the object’s data through this reference rather than directly accessing the locally declared variables.

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

Sidebar

Related Questions

I have an inline member function defined under class MyClass int MyClass::myInlineFunction(); This function
I have function getCartItems in cart.js and I want to call that function in
Inside of a static member function I need to get the type. class MyClass
I have a overriden function in my class, that adds an event handler like
I have a class that handles events from a WinForms control. Based on what
Quick question: If I have a very large function/sub in a class that is
I have one javasctipc class... Lets call it X. myClass = new X(bunc, of,
I have a module that looks something like this: def __myFunc(): ... class MyClass(object):
I currently have a method within my class that has to call other methods,
I have 3 function in my class B. These three function have to access

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.