Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > c and macos X programming

c and macos X programming
Thread Tools
Dedicated MacNNer
Join Date: Mar 2002
Status: Offline
Reply With Quote
Feb 21, 2003, 09:01 AM
 
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
Reply With Quote
Feb 21, 2003, 10:51 AM
 
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.
     
DevNine  (op)
Dedicated MacNNer
Join Date: Mar 2002
Status: Offline
Reply With Quote
Feb 21, 2003, 12:51 PM
 
But an api is an api ,whatever language I address it from right ?
     
Mac Elite
Join Date: Sep 2000
Location: Tempe, AZ
Status: Offline
Reply With Quote
Feb 21, 2003, 01:41 PM
 
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
Reply With Quote
Feb 21, 2003, 02:02 PM
 
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
Reply With Quote
Feb 21, 2003, 03:41 PM
 
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
Reply With Quote
Feb 22, 2003, 04:12 AM
 
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
Reply With Quote
Feb 22, 2003, 07:45 AM
 
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
Reply With Quote
Feb 22, 2003, 02:41 PM
 
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
Reply With Quote
Feb 22, 2003, 02:53 PM
 
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
Reply With Quote
Feb 22, 2003, 03:17 PM
 
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
Reply With Quote
Feb 22, 2003, 03:21 PM
 
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
Reply With Quote
Feb 23, 2003, 04:28 AM
 
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
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 08:49 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2