• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Accessing objective-c from c
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Accessing objective-c from c


  • Subject: Re: Accessing objective-c from c
  • From: "Clark S. Cox III" <email@hidden>
  • Date: Fri, 30 May 2003 08:45:54 -0400

On Friday, May 30, 2003, at 01:56 US/Eastern, James Howard wrote:

I've been playing around with unsanity's ape sdk lately. Its pretty cool, but to do anything complex it requires that I make a lot of objective-c calls from c. I've figured out how to send and get return values for all of the possible objective-c message types except for those methods that return just a plain int or something. When a structure is the return value, I can do something like this:
NSRect rect;
objc_msgSend_stret(&rect, someView, sel_registerName("frame"));
and that gets me the rect all well and good. (that would be equivalent to NSRect rect = [someView frame];)
But lets say I want to get an int (int level = [someWindow level];)
int level;
objc_msgSend_stret(&level, someWindow, sel_registerName("level"));
and that won't work at all. I think it might be doing something like sticking the return value into an objc_ivar struct or something to that effect, but I haven't been able to track it down to the point where I get anything that works. So what is the magic combination I need to get the int return value?

The "stret" in "objc_msgSend_stret" stands for "structure return", and is only used when the result cannot be returned in a register. However, for int's, the result *can* be returned in a register, so you should use the plain objc_msgSend() function.

Of course, I'd have to second Finlay's statement that you shouldn't really need to do this. You can always let the compiler do what it's good at, and do something like this:


/*File Bridge.h*/
extern int CallSomeMethod();
/*End File*/


/*File Bridge.m*/
int CallSomeMethod()
{
return [someObject someMethod];
}
/*End File*/

/*File SomeFile.c*/
#include "Bridge.h"
void foo()
{
int i = CallSomeMethod();
}
/*End File*/


--
http://homepage.mac.com/clarkcox3/
email@hidden
Clark S. Cox, III
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

  • Follow-Ups:
    • Re: Accessing objective-c from c
      • From: James Howard <email@hidden>
References: 
 >Accessing objective-c from c (From: James Howard <email@hidden>)

  • Prev by Date: Re: simple float/double question
  • Next by Date: Re: Carbon : start-up volume name/path as POSIX
  • Previous by thread: Re: Accessing objective-c from c
  • Next by thread: Re: Accessing objective-c from c
  • Index(es):
    • Date
    • Thread