C Board  

Go Back   C Board > Community Boards > General Discussions

Reply
 
LinkBack Thread Tools Display Modes
Old 01-25-2005, 06:30 AM   #1
Registered User
 
Join Date: Aug 2004
Posts: 77
Mac OS X Programming

I recently recieved a Mac, complete with OS X. I was curious about programming on it. From all the reading I've done on it it seems the two C API sets are Carbon and Cocoa.

Cocoa uses something called Objective-C, which is Apple's enhanced C language, not sure why they didn't use C++ since its already pretty popular and includes the object oriented stuff that was included in Objective-C. There may be more there, I'm not keen on learning another language (particularly a proprietary one) for a platform I'm not sure if I'm going to keep using.

Carbon is a straight C API. However, it appears that its an intermediary API for those converting from the old Mac OS API's. Which kinda sounds like Apple will keep it around until everyone is up to date then drop support, thats just speculation by me though and I've been labeled cynical before.

So whats the deal? Anyone know if OS X has a C or C++ API that is guarenteed to be supported in the forseeable future?
Exile is offline   Reply With Quote
Old 01-25-2005, 06:50 AM   #2
Registered User
 
Join Date: May 2004
Posts: 1,362
Are you looking to make GUI apps?
__________________
sand_man is offline   Reply With Quote
Old 01-25-2005, 07:28 AM   #3
Registered User
 
Join Date: Aug 2004
Posts: 77
Thats definately on the list. Most of the things I've programmed of late were various utilities and the like, so I have a requirement for threads, sockets and file/directory access as well.
Exile is offline   Reply With Quote
Old 01-25-2005, 08:13 AM   #4
I like code
 
Rouss's Avatar
 
Join Date: Apr 2004
Posts: 131
Quote:
Originally Posted by Exile
Cocoa uses something called Objective-C, which is Apple's enhanced C language, not sure why they didn't use C++ since its already pretty popular and includes the object oriented stuff that was included in Objective-C.
Unlike C++, Obj C really is an extension to C. An Obj C program is really just a C program, using special C headers to allow you to use the Obj C object designs.

I've done a few projects for class in Obj C and personally I prefer it to C++. I wish it was used more than it is.

Also, I have a few friends that program Cocoa apps. They seem to enjoy it and think it is worthwhile, although I've never heard them mention Carbon.
Rouss is offline   Reply With Quote
Old 01-25-2005, 08:41 AM   #5
Registered User
 
Join Date: Aug 2004
Posts: 77
Quote:
Originally Posted by Rouss
Unlike C++, Obj C really is an extension to C. An Obj C program is really just a C program, using special C headers to allow you to use the Obj C object designs.
I'll admit to not researching Objective-C fully before coming to that conclusion, so I'm all set to be proven wrong.

These headers, is it like including iostrem where it allows non-standard lookging function calls like cin and cout? Or do they simply add additional functions?

Since Objective-C is object oriented I imagine they have to be adding more than just additional functions.

I've also heard some talk about Objective-C++ where its Objective-C but also lets you use all of C++ as well. So I guess Mac does permit C++ programming.

I guess the question then becomes how different really is Objective-C from ANSI C? If its just a a few headers, it hardly seems worth renaming it.

Quote:
Originally Posted by Rouss
Also, I have a few friends that program Cocoa apps. They seem to enjoy it and think it is worthwhile, although I've never heard them mention Carbon.
Carbon apparently is just a transitional API, intended for porting old Mac OS apps to OS X. I don't know if it was intended for any use beyond that. It certainly hasn't gotten much press so at the very least Apple isn't pushing the subject at all if that says anything.
Exile is offline   Reply With Quote
Old 01-25-2005, 08:49 AM   #6
pronounced 'fib'
 
FillYourBrain's Avatar
 
Join Date: Aug 2002
Posts: 2,289
mac definitely allows c++ through g++ and X programming. Granted it isn't old school mac programming, but they've gone in the bsd direction for a reason.
__________________
"You are stupid! You are stupid! Oh, and don't forget, you are STUPID!" - Dexter
FillYourBrain is offline   Reply With Quote
Old 01-25-2005, 09:43 AM   #7
Crazy Fool
 
Perspective's Avatar
 
Join Date: Jan 2003
Location: Canada
Posts: 2,596
>>Which kinda sounds like Apple will keep it around until everyone is up to date then drop support,

<my-opinion>Mac will never drop carbon</my-opinion>
Perspective is offline   Reply With Quote
Old 01-25-2005, 01:05 PM   #8
I like code
 
Rouss's Avatar
 
Join Date: Apr 2004
Posts: 131
Quote:
Originally Posted by Exile
I'll admit to not researching Objective-C fully before coming to that conclusion, so I'm all set to be proven wrong.
Whoa, I wasn't trying to prove anyone wrong (I don't have enough expertise to do that), I was just explaining the difference between the two.

Quote:
Originally Posted by Exile
These headers, is it like including iostrem where it allows non-standard lookging function calls like cin and cout? Or do they simply add additional functions?

Since Objective-C is object oriented I imagine they have to be adding more than just additional functions.
It's not really like the cpp headers. You would use #import <objc/object.h> (objc encourages using import instead of include, but you can use either one). And they're are other headers you can use, such as one for a list object.
And really all the header does is allow a few new functions and data types, and allow a few new syntactical ways of dealing with objects. I think they are based on the way smalltalk handles objects. Such as
Code:
id MyObject; /*id is basically a void pointer that CAN be dereferenced*/
MyObject = new ObjectClass; /*make a new instance of ObjectClass*/
/* could also be written */
ObjectClass *MyObject = new ObjectClass; \* or something like that */
/*to call object methods looks like this */
[MyObject MethodName:Argument]; /*Calls MyObject method MethodName, and passes it Argument ] */
int myNum;
myNum = [MyObject MethodThatReturnsInt:Arg]; /*This calls an object method that returns a value, and I am storing the value in myNum.*/
/*and when you're done you have to free the object*/
[MyObject free]; /* you can even overload the free method */
So, you can see the difference between C++ and ObjC. My apologies to everyone who was bored by that.

Quote:
Originally Posted by Exile
I've also heard some talk about Objective-C++ where its Objective-C but also lets you use all of C++ as well. So I guess Mac does permit C++ programming.
You can do all kinds of programming on Mac; C, ObjC, C++, perl, asm, etc.

Quote:
Originally Posted by Exile
I guess the question then becomes how different really is Objective-C from ANSI C? If its just a a few headers, it hardly seems worth renaming it.
Beyond what you can use when you include the headers, it's not different than ANSI C. You can include the objc headers and write a plain non objective C program, and it will work just the same as if you didn't include the headers. Maybe not worth the name change. It might be more intuitive to say that I wrote a C program with the Objective C headers. I really don't like C++'s name, because many times I have heard, as I know most everyone else here has, this question, "Isn't C outdated? Why don't you use C++?" It's like people think that when C++ was created that it replaced C, and C should have crawled into a hole and died.
Rouss is offline   Reply With Quote
Old 01-25-2005, 01:16 PM   #9
Just one more wrong move.
 
-KEN-'s Avatar
 
Join Date: Aug 2001
Posts: 3,232
Quote:
Originally Posted by Perspective
>>Which kinda sounds like Apple will keep it around until everyone is up to date then drop support,

<my-opinion>Mac will never drop carbon</my-opinion>
Yeah. Important applications of theirs like Finder are written in Carbon.
__________________
Gays can't love like real people

entropysink.com -- because arses weren't designed for running websites.
-KEN- is offline   Reply With Quote
Old 01-25-2005, 01:48 PM   #10
Registered User
 
Join Date: Aug 2004
Posts: 77
Quote:
Originally Posted by Rouss
Whoa, I wasn't trying to prove anyone wrong (I don't have enough expertise to do that), I was just explaining the difference between the two.
I know, I was just saying that my opinions were very shortsighed and sound pretty negative. I knew it and was stating that I expected them to be wrong.

Quote:
Originally Posted by Rouss
You can do all kinds of programming on Mac; C, ObjC, C++, perl, asm, etc.
I thought they permitted all thee C languages (any better way to say that?) in one source file and the compiler would accept it and generate an executable?


Thanks for all the details on that, I haven't seen much that gives the low down on this stuff. That clears up a lot of the questions I had on Objective-C.
Exile is offline   Reply With Quote
Old 01-25-2005, 02:41 PM   #11
I like code
 
Rouss's Avatar
 
Join Date: Apr 2004
Posts: 131
Quote:
Originally Posted by Exile
I thought they permitted all thee C languages (any better way to say that?) in one source file and the compiler would accept it and generate an executable?
I'm not sure what you mean. I don't think you can write a C program and compile it as C++, unless you include the C headers the way c++ likes it, <cstdio>, <cstring>, etc. And I don't think you can compile a C++ file as C... But I don't really know about this. Maybe somebody else would be better to answer this question than me.
Rouss is offline   Reply With Quote
Old 01-25-2005, 02:48 PM   #12
Registered User
 
Join Date: Aug 2004
Posts: 77
Quote:
Originally Posted by Rouss
I'm not sure what you mean. I don't think you can write a C program and compile it as C++, unless you include the C headers the way c++ likes it, <cstdio>, <cstring>, etc. And I don't think you can compile a C++ file as C... But I don't really know about this. Maybe somebody else would be better to answer this question than me.
From what I was reading, the compiler isn't limited to just C and/or Objective-C code. You can mix in C++ as well and it won't get upset.

The Mac compiler (not necessarily the gcc port to OS X, I'm not sure what it will take) will handle C, C++, and Objective-C all in one source file. Naturally you have to include all the required headers and libraries to make it work.

Hope that clears up what I was saying.
Exile is offline   Reply With Quote
Old 01-25-2005, 03:13 PM   #13
I like code
 
Rouss's Avatar
 
Join Date: Apr 2004
Posts: 131
So you could include <stdio> and <iostream> and write a hybrid c/c++ program? Is this just a Mac thing, or is it true of all versions of gcc? I guess I could test that question myself. I don't write much c++ anyway, so it doesn'y really matter.
Rouss is offline   Reply With Quote
Old 01-25-2005, 03:36 PM   #14
Registered User
 
Join Date: Aug 2004
Posts: 77
Quote:
Originally Posted by Rouss
So you could include <stdio> and <iostream> and write a hybrid c/c++ program? Is this just a Mac thing, or is it true of all versions of gcc? I guess I could test that question myself. I don't write much c++ anyway, so it doesn'y really matter.
Thats pretty standard in C++ compilers. Visual studio and gcc will permit that. Those are the only compilers I use so I can't say for sure that all compilers will permit it, but so far as I an tell they all will.
Exile is offline   Reply With Quote
Old 05-06-2005, 03:12 PM   #15
Registered User
 
Join Date: Apr 2004
Posts: 21
Maybe I can help on this one. Cocoa and Objective C are nothing but systems to communicate with a UI made with Interface Builder. You can use C or C++ in your ObjC files, by suffixing your files with .m or .mm. Cocoa was created with fast Mac OS X programming in mind, and does not work in Mac Classic. Carbon is a straight C or C++ file that uses much more code to communicate with the user interface. Carbon requires much more code, but in return there are many more things that you can do with it, and it runs in Mac Classic. You can mix Carbon code into Cocoa code, but you cannot use control the same UI with the two different codes. Carbon probably won't be replaced any time soon. There is a lot more info on the Apple Developer Website.
OSDever is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
running binaries built on Mac OS X 10.4 on Mac OS X 10.5 rak1986 C Programming 1 02-03-2009 04:45 AM
Mac OS X aliases rak1986 C Programming 4 01-21-2009 12:11 PM
inquiry from a hungry mac os x user terabyter C Programming 3 06-23-2006 09:04 AM
Mac OS X Users/C programmers? petermichaux C Programming 15 12-01-2003 10:35 PM
Assembly & Mac OS X kristy Tech Board 2 07-29-2003 04:29 PM


All times are GMT -6. The time now is 06:07 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22