 |
 |
c and macos X programming
|
 |
|
 |
|
Dedicated MacNNer
Join Date: Mar 2002
Status:
Offline
|
|
Quick Question,
Can I write in c (not ++) and use the cocoa api ? Any problems?
|
|
|
| |
|
|
|
 |
|
 |
|
Addicted to MacNN
Join Date: Mar 2000
Location: London, UK
Status:
Offline
|
|
The Cocoa API is written in Objective-C, not C++ or C. Obj-C is a small set of extensions to C, nothing like C++. If you want to write in pure C, you'll have to use Carbon, but there's honestly no point.
|
|
|
| |
|
|
|
 |
|
 |
|
Dedicated MacNNer
Join Date: Mar 2002
Status:
Offline
|
|
But an api is an api ,whatever language I address it from right ?
|
|
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: Sep 2000
Location: Tempe, AZ
Status:
Offline
|
|
Yeah, no probs using C. If you were to use Cocoa from something other than C or C++ (or Java), you'd need a language bridge. For example, you couldn't write an ADA program and call Cocoa, at least, not easily. It's hard to write code from a mental institution. 
|
Geekspiff - generating spiffdiddlee software since before you began paying attention.
|
| |
|
|
|
 |
|
 |
|
Addicted to MacNN
Join Date: Mar 2000
Location: London, UK
Status:
Offline
|
|
What do you mean? You can call Obj-C from within C functions, of course, but you can't call Cocoa from C -- except for the few APIs which actually are pure C
An API is an API, yes, but an API is normally exposed in one particular language. Cocoa is a set of Obj-C objects, so to use them you're going to need to use Obj-C or some bridge.
|
|
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: Sep 2000
Location: Tempe, AZ
Status:
Offline
|
|
Originally posted by Angus_D:
What do you mean? You can call Obj-C from within C functions, of course, but you can't call Cocoa from C -- except for the few APIs which actually are pure C 
I assume you mean C++. You can call Cocoa from C++ using objective-C++. Rename your .m file to .mm and mix metaphors to your hearts content. And wait 45 minutes to compile "Hello World!", of course.
|
Geekspiff - generating spiffdiddlee software since before you began paying attention.
|
| |
|
|
|
 |
|
 |
|
Addicted to MacNN
Join Date: Mar 2000
Location: London, UK
Status:
Offline
|
|
Originally posted by smeger:
I assume you mean C++. You can call Cocoa from C++ using objective-C++. Rename your .m file to .mm and mix metaphors to your hearts content. And wait 45 minutes to compile "Hello World!", of course.
No, I meant C, but your point stands too
Code:
void FunThing( id blah ) {
[blah doSomething:@"Fwee"];
MyOtherCFunction();
}
is what i meant. Of course, this should be obvious, since Obj-C is just a superset of C, but I was just trying to clarify any confusion DevNine had 
|
|
|
| |
|
|
|
 |
|
 |
|
Dedicated MacNNer
Join Date: Nov 2000
Status:
Offline
|
|
I think you could use pure C syntax and use functions like objc_msgSend as long as you link against the correct libraries. If you decide to go that route, you're a braver man than I am. Have a look at /usr/include/objc/*.
|
|
|
| |
|
|
|
 |
|
 |
|
Clinically Insane
Join Date: Oct 2001
Location: San Diego, CA, USA
Status:
Offline
|
|
Originally posted by int69h:
I think you could use pure C syntax and use functions like objc_msgSend as long as you link against the correct libraries. If you decide to go that route, you're a braver man than I am. Have a look at /usr/include/objc/*.
It seems like you'd still more or less have to use Obj-C features like selectors and classes, which aren't found in C.
|
|
Chuck
___
"Instead of either 'multi-talented' or 'multitalented' use 'bisexual'."
|
| |
|
|
|
 |
|
 |
|
Addicted to MacNN
Join Date: Mar 2000
Location: London, UK
Status:
Offline
|
|
You wouldn't want to use objc_msgSend directly. That'd just be silly.
|
|
|
| |
|
|
|
 |
|
 |
|
Clinically Insane
Join Date: Oct 2001
Location: San Diego, CA, USA
Status:
Offline
|
|
Originally posted by Angus_D:
You wouldn't want to use objc_msgSend directly. That'd just be silly.
Not that much sillier than trying to use Cocoa with pure C....
|
|
Chuck
___
"Instead of either 'multi-talented' or 'multitalented' use 'bisexual'."
|
| |
|
|
|
 |
|
 |
|
Dedicated MacNNer
Join Date: Nov 2000
Status:
Offline
|
|
Angus,
The example code you posted was objective-c. I realize no sane person would attempt this.
Chuckit,
Code:
struct objc_class {
struct objc_class *isa;
struct objc_class *super_class;
const char *name;
long version;
long info;
long instance_size;
struct objc_ivar_list *ivars;
struct objc_method_list **methodLists;
struct objc_cache *cache;
struct objc_protocol_list *protocols;
};
Looks like C to me.
Writing a Cocoa app using only C syntax, and not relying on a wrapper library looks like an excercise in pain, but it seems possible.
|
|
|
| |
|
|
|
 |
|
 |
|
Addicted to MacNN
Join Date: Mar 2000
Location: London, UK
Status:
Offline
|
|
Of course. Obj-C is pretty much converted to C before compilation anyway. However it's advised you don't use the objc runtime api specifically because they're not guaranteed to be stable 
|
|
|
| |
|
|
|
 |
 |
|
 |
|
|
|
|
|

|
|
 |
Forum Rules
|
 |
 |
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
 |
 |
 |
 |
|
 |
|