Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

pilotError

macrumors 68020
Original poster
Apr 12, 2006
2,237
4
Long Island
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?
 

robbieduncan

Moderator emeritus
Jul 24, 2002
25,611
893
Harrogate
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.
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:

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?

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

Krevnik

macrumors 601
Sep 8, 2003
4,101
1,312
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 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.

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

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)...
 

pilotError

macrumors 68020
Original poster
Apr 12, 2006
2,237
4
Long Island
Unfortuantely, my advice is that you probably don't want to use Windows to learn Obj-C.

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. :)
 

Krevnik

macrumors 601
Sep 8, 2003
4,101
1,312
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. :)

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.
 

robbieduncan

Moderator emeritus
Jul 24, 2002
25,611
893
Harrogate
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.

Interesting. I read this (from http://developer.apple.com/leopard/overview/tools.html):

Apple said:
The new garbage collector is a tuned, high-performance implementation that makes tedious memory management in Cocoa applications a thing of the past. It works hand-in-hand with the strengths of Objective-C, allowing you to never worry about memory management of Cocoa objects, yet allowing you full access to C-based structures and functions that use malloc and free or reference counting systems. And, it's an opt-in system. This means that if you have an existing codebase that you want to run unchanged in Leopard, you don't have to do a thing.

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!
 

Krevnik

macrumors 601
Sep 8, 2003
4,101
1,312
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.

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.
 

robbieduncan

Moderator emeritus
Jul 24, 2002
25,611
893
Harrogate
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.

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

Krevnik

macrumors 601
Sep 8, 2003
4,101
1,312
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...

Perhaps, I am not sure where that is in the documentation now. :)
 

Catfish_Man

macrumors 68030
Sep 13, 2001
2,579
2
Portland, OR
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).
 

Krevnik

macrumors 601
Sep 8, 2003
4,101
1,312
Apple's linker/runtime is different than what is in GCC proper.

2004 email discussion from GCC:

http://gcc.gnu.org/ml/gcc-patches/2004-06/msg00187.html

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.
 

Nutter

macrumors 6502
Mar 31, 2005
432
0
London, England
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.
 

pilotError

macrumors 68020
Original poster
Apr 12, 2006
2,237
4
Long Island
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:
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.