2005/12/09 v 5:06, Miguel Menchu:
> Hi,
>
> I started this week learning about objective-c, in an attempt
> to use the bluetooth libraries in os X. Since I don't know
> objective c that well
> yet, I was hoping to use the api from C. I read a couple of online
> docs but I need help with a couple of questions. So far the most
> useful
> doc has been this:
http://lists.gnu.org/archive/html/discuss-
> gnustep/2002-07/msg00091.html
>
> My questions are these:
> - Once we've compiled the objective-c code and have a filename.o
> file, how do we proceed to include that in c? I tried doing
> #include filename.o, even filename.m but nothing happened.
The include directive is for including source files (header files in
most cases). If you want to link C and ObjC object files together,
you can do that in the same way as if they were all C object files,
it doesn't matter. And remember that gcc supports both languages so
you don't have to care about these details.
>
> - If you were able to visit the link above, there's info on how to
> call the object's methods; however there's no info regarding how to
> declare the type of that object. For example suppose we have a
> objective-c file with name filename.o and a method "dosomething".
> From the linke above I gather i need to call it like this:
> void c_function(filename* anObject)
> {
> [anObject dosomething];
> }is this correct? But the compiler complains that the class
> filename is not declared! Please help.
The fact that most source file names (and object file names) are the
same as the contained class names is just a coincidence. [anObject
doSomething] (calling ObjC methods) constructions can be used only in
ObjC source, not in plain C. What you probably want to do is this:
Foo.m - ObjC file containing C functions which call ObjC methods
Foo.h - declarations of functions in Foo.m
Bar.c - #includes Foo.h and uses its functions.
However, you can't use ObjC classnames (filename in your example) in
the pure C code (and therefore they shouldn't appear in Foo.h). You
may instead consider using ObjC (.m) source files in the whole
project to avoid these problems. Remember that C is just a subset of
Obj-C, so you can use plain C in most of the project and ObjC
whenever you need.
--
Adam Nohejl
Loki Software
mailto:
adam@loki...
http://lokisw.com
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Objc-language mailing list (
Objc-language@list...)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/objc-language/subscriber%40opensubscriber.com
This email sent to
subscriber@open...
opensubscriber is not affiliated with the authors of this message nor responsible for its content.