Questions about GNU objective-c

Discussion in 'Mac Programming' started by pilotError, Jun 1, 2007.

  1. pilotError macrumors 68020

    pilotError

    Joined:
    Apr 12, 2006
    Location:
    Long Island
    #1
    I have time at work, so I downloaded GNUstep and gcc to start learning objective-c.

    When going through the beginners guide at http://www.otierney.net/objective-c.html

    I discovered some differences from the GNU gcc version and the Apple version of gcc.

    My questions to anyone who knows about this stuff is...

    Does Apple give back to the GNU process? I assume they have to, but there are some obvious differences with what I'm using (exception handling in particular) that is not available in the version of gcc that I'm using.

    I didn't go look at the gcc source tree to see if someones working on it, but you get the idea.

    When objective-c 2.0 rolls around, how long does it typically take to roll the updates into the base package? Particularly, I'd like to avoid the older style memory management if its changing drastically. Or should I just bite the bullet and learn it?

    Is there a better version of gcc that runs under windows than they cygwin / ming32 version 3.4.2 to learn on?
     
  2. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #2
    Yes, they submit all their changes back, but there is no requirement for the GCC guys to accept them. For example they refused the Objective-C++ changes for ages (and may not have accepted them yet?) :eek:

    Apple will probably provide the changes very quickly, but they are mostly in the runtime, not the compiler. I'm not sure if Apple share their runtime or not. Even if they do there is no reason to believe that it will appear in GCC all that quickly.

    I'd learn to do memory management the current way. GC is great in some cases, but not in all. Apple expect that you will want to mix and match and take full control where performance is critical and let the GC system take the strain else where...
     
  3. Krevnik macrumors 68040

    Krevnik

    Joined:
    Sep 8, 2003
    #3
    Apple actually operates a fork off of the GNU mainline CVS. Quite a few of their changes to GCC wind up there before they even wind up in XCode. I remember compiling their fork of 4.x before Tiger arrived to play around with the optimizer.

    Obj-C 2.0 is a mix of runtime and compiler changes. Things in Obj-C 2.0 that will work in apps you want to target Tiger with, are compiler bits that will likely make it into plain GCC eventually. Things like GC are a runtime affair.

    Just to correct you a bit, GC will only be available in an on/off fashion per product. You cannot mix-and-match, since the GC will be required to track all your pointers in order to actually garbage collect, like Java and the .NET CLR. In theory, you /could/ mix-and-match, but you could get into some interesting bad states if you do.

    To the OP... Unfortuantely, my advice is that you probably don't want to use Windows to learn Obj-C. Apple's runtime and additional frameworks are rather robust, and GNUstep + vanilla GCC just won't cut it in places, much like Mono doesn't cut it for real C# development. An example is the VERY nice Unit Testing framework available in XCode (along with OCMock)...
     
  4. pilotError thread starter macrumors 68020

    pilotError

    Joined:
    Apr 12, 2006
    Location:
    Long Island
    #4
    I absolutely agree with you.

    However... I'm a consultant, and there are no Macs anywhere near here (at work). I figured since I had some down time, I'd get started on the base language.

    Nothing rocket science so far, some pretty cool features though. :)
     
  5. Krevnik macrumors 68040

    Krevnik

    Joined:
    Sep 8, 2003
    #5
    Yeah, the problem is that these rapid application development languages are more dependant on an extensive framework (.NET, Cocoa, etc) to interact with the OS... GNUstep's implementation, the last time I looked, was lacking in rather basic areas that Apple handled for you.
     
  6. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #6
    Interesting. I read this (from http://developer.apple.com/leopard/overview/tools.html):

    As meaning you could mix and match. I do see that you could read this as meaning that all Obj-C objects would be GC if you turned it on but you have to manage non-class structures yourself (so anything you create via Core Foundation or the lower level bits of Quartz), but as Obj-C objects are just reference-counted C structures I had thought that the option was there to turn off GC for some objects.

    If it's per-target there is still the possibility of putting non-GC code in a Framework and including it in a GC app. Again this seems to raise a number of potential issues!
     
  7. Krevnik macrumors 68040

    Krevnik

    Joined:
    Sep 8, 2003
    #7
    Well, not really, the ref-counting is done in Obj-C code, as part of NSObject (in the Cocoa runtime), rather than part of Object or in the Obj-C runtime.

    BTW, CoreFoundation objects are Cocoa objects, with a C-friendly API for accessing them. Try using CF to get a CFStringRef object, and then typecast it into NSString *, and call it. It works. Create an NSString, and typecast the pointer into a CFStringRef to pass into CF APIs... that also works.

    Garbage Collection is enabled as a build option, and it generates code that will turn on GC in the runtime for your process. As for your comment about frameworks, that is a good point, since frameworks + app all need to be GC enabled for it to work.
     
  8. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #8
    I was more thinking about some of the less friendly aspects of CoreGraphics with all the CG...Create functions and their respective free functions. I assume these are the "Reference counted C structures" Apple were talking about...
     
  9. Krevnik macrumors 68040

    Krevnik

    Joined:
    Sep 8, 2003
    #9
    Perhaps, I am not sure where that is in the documentation now. :)
     
  10. Catfish_Man macrumors 68030

    Catfish_Man

    Joined:
    Sep 13, 2001
    Location:
    Portland, OR
    #10
    I'm pretty sure GC control is finer-grained than just an on-off switch. I don't remember the details though (not that it matters, due to the %&$^ nda).
     
  11. mdriftmeyer macrumors 68030

    mdriftmeyer

    Joined:
    Feb 2, 2004
    Location:
    Pacific Northwest
    #11
  12. Krevnik macrumors 68040

    Krevnik

    Joined:
    Sep 8, 2003
    #12
    The Mach-O linker is supported by GCC, but off by default since only one platform supports it... Darwin. Apple has some other extensions that I don't think have reached mainline for fat Mach-O binaries.

    As for the runtime, Apple has a much-extended runtime for Objective-C, built around the core one. GNUStep was supposed to replicate a bunch of it.
     
  13. Nutter macrumors 6502

    Joined:
    Mar 31, 2005
    Location:
    London, England
    #13
    As I understand it the GC is indeed either fully on or fully off. This includes all frameworks. The description of GC as being "opt-in" just means that by default it is turned off. If you turn it on, everything will be garbage collected.
     
  14. pilotError thread starter macrumors 68020

    pilotError

    Joined:
    Apr 12, 2006
    Location:
    Long Island
    #14
    I was actually able to get through all of the tutorial I posted above with the exception of well... Exceptions.

    The tutorial didn't include any graphical components, which is fine, I wanted to get through the base language.

    Thanks for the info on the gcc. The environment isn't THAT bad, but if your following this thread with any interest at all, its workable.

    I'll try and get through some of the gui stuff at work, since my kids don't let me get on my Mac very often :eek:
     

Share This Page