discuss-gnustep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to call objective-c method from c ?


From: Pascal Bourguignon
Subject: Re: How to call objective-c method from c ?
Date: Tue, 16 Jul 2002 06:38:06 +0200 (CEST)

> From: "Yen-Ju Chen" <yjchenx@hotmail.com>
> Date: Mon, 15 Jul 2002 22:38:32 -0400
> 
> Hi,
> 
>   How to call objective-c method from c function ?
>   Something like that:
> 
>   @implement TestObject
> 
>   void c_function()
>   {
>     call(objec_method, NULL);
>   }
> 
>   - (void) objec_method
>   {
>   }
> 
>   ...
> 
>   @end


Objective-C is a strict superset of C. (Contrarily to C++ where some C
constructs are not allowed, but that's not the point).

When you  compile a C program  with the Objective-C  compiler, you can
use  all the  Objective-C  construct in  the  C parts  and  all the  C
constructs in the Objective-C parts.  There's no differences.

Therefore, you would send a message  to an Objective-C object from a C
function exactly the same way you'd do it from an Objective-C method:

         void c_function(TestObject* anObject)
         {
             [anObject objec_method];
         }


The only thing is that you'll have to compile the C functions with the
Objective-C compiler (gcc -x objective-c).





Additionnaly,  if you insisted  to compile  the C  functions with  a C
compiler (or  a C++  compiler, for example),  you could still  send an
Objective-C  message  to an  Objective-C  object  using the  low-level
Objective-C API, but that level  is not standardized and depend on the
Objective-C runtime used (see objc_msg_sendv() in objc-api.h).



-- 
__Pascal_Bourguignon__                   http://www.informatimago.com/
----------------------------------------------------------------------



reply via email to

[Prev in Thread] Current Thread [Next in Thread]