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

moonman239

Cancelled
Original poster
Mar 27, 2009
1,541
32
I use Objective-C for iPhone app development. Now, I want to tackle C so that I can build modules for Python. How do I go about doing this?
 
You just need to study up a bit on procedural C (or C++) and read up a bit on how to structure Python modules – like here, or search a bit on your own.

Procedural C is a bit more terse than Objective-C, which can make it harder to read if you are not used to it, but it is not really an enormous leap. Not having ivars may also take a little getting used to.
 
I use Objective-C for iPhone app development. Now, I want to tackle C so that I can build modules for Python. How do I go about doing this?

Get some books, K&R old but classic, C in a nutshell (O'Reilly) is good and cover C99. Also get hold of the standard, or at least a draft version to consult in moments of doubt. Then write and read lots of code, especially pointer and memory allocation intensive code to get that down, data structures, trees, queues, graphs etc. involves a lot of that if you do it in C.
 
You might be coding in C already.

Objective C is a strict superset of C. Just use Objective C, without using classes, objects and methods, and you will be using C. Then put the code in .c files instead of .m files, and you're done.

You can do almost the same things in C as in (manually memory managed) Objective C by using structs and passing them around as explicit function parameters (instead of as the hidden parameters in Obj C methods).

But have you checked into coding Python modules in Objective C?
 
Get some books, K&R old but classic, C in a nutshell (O'Reilly) is good and cover C99.

I'd avoid reading K&R: its coverage of C is frankly naive. You want something that isn't afraid to dissect C's many warts and shortcomings and discuss how best to work around them in real-world use.

Honestly, if the OP already knows ObjC then the main task is learn their way around Python's C API. There's no need to muck around with malloc/free and other clunky C-isms unless you're wrapping C libraries that require their use.

Alternatively, OP might want to consider sticking with ObjC, and just use PyObjC to access ObjC frameworks directly from Python. Not sure if PyObjC works on iOS, but it's a mature and capable technology, fully supported on OS X, and even included in OS X's own Python 2.x as standard.
 
I'd avoid reading K&R: its coverage of C is frankly naive. You want something that isn't afraid to dissect C's many warts and shortcomings and discuss how best to work around them in real-world use.

Sure, and that's why I said books, plural, it's still a good book to have read imho.

Honestly, if the OP already knows ObjC then the main task is learn their way around Python's C API. There's no need to muck around with malloc/free and other clunky C-isms unless you're wrapping C libraries that require their use.

Yeah, but that's just the interface, all implementation will be in C. Since the OP asked assumably there is a need for it and although you're indirectly using C from Obj-C it's not really the same if you drop all statements using [] and @. So if you want to get up to speed on the parts of C that's not really used from Obj-C normally, I think it's a good idea to focus on those exact parts.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.