Mac OS X Programming

This is a discussion on Mac OS X Programming within the A Brief History of Cprogramming.com forums, part of the Community Boards category; I recently recieved a Mac, complete with OS X. I was curious about programming on it. From all the reading ...

  1. #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?

  2. #2
    ---
    Join Date
    May 2004
    Posts
    1,379
    Are you looking to make GUI apps?

  3. #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.

  4. #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.

  5. #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.

  6. #6
    pronounced 'fib' FillYourBrain's Avatar
    Join Date
    Aug 2002
    Posts
    2,297
    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

  7. #7
    Crazy Fool Perspective's Avatar
    Join Date
    Jan 2003
    Location
    Canada
    Posts
    2,640
    >>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>

  8. #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.

  9. #9
    Just one more wrong move. -KEN-'s Avatar
    Join Date
    Aug 2001
    Posts
    3,230
    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.

  10. #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.

  11. #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.

  12. #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.

  13. #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.

  14. #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.

  15. #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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Mac OS X Users/C programmers?
    By petermichaux in forum C Programming
    Replies: 16
    Last Post: 04-18-2011, 06:36 AM
  2. Replies: 1
    Last Post: 02-03-2009, 03:45 AM
  3. Mac OS X aliases
    By rak1986 in forum C Programming
    Replies: 4
    Last Post: 01-21-2009, 11:11 AM
  4. inquiry from a hungry mac os x user
    By terabyter in forum C Programming
    Replies: 3
    Last Post: 06-23-2006, 09:04 AM
  5. Assembly & Mac OS X
    By kristy in forum Tech Board
    Replies: 2
    Last Post: 07-29-2003, 04:29 PM

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