Mac How do I go from programming in Objective-C to coding in C?

moonman239

macrumors 68000
Original poster
Mar 27, 2009
1,524
22
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?
 

Sydde

macrumors 68020
Aug 17, 2009
2,119
3,758
IOKWARDI
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.
 

subsonix

macrumors 68040
Feb 2, 2008
3,551
79
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.
 

firewood

macrumors 604
Jul 29, 2003
7,755
1,013
Silicon Valley
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?
 

hhas

macrumors regular
Oct 15, 2007
126
0
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.
 

subsonix

macrumors 68040
Feb 2, 2008
3,551
79
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.
 

Similar threads

  • view60
1
Replies
1
Views
220
  • PinkyMacGodess
2
Replies
2
Views
673
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.