combining objective c and c

Discussion in 'iOS Programming' started by printf, Aug 1, 2009.

  1. printf macrumors regular

    Joined:
    Aug 27, 2008
    #1
    i've heard it mentioned that it's possible to write c code along side objective c, and i'm interested in learning how to accomplish this. this will decrease the amount of time it takes to get some simple iphone apps up and running because it will keep me from having to port many libraries of c/c++ code over to objective c (NOT a fun task). and in line with that thought, since i do a lot of windows programming, it would obviously be nice to have some portability between platforms so code i write on one can easily be moved over with little effort. makes sense, right? :)

    i would appreciate articles/tutorials/references that explain this, or if this is a relatively trivial thing that can be explained in a paragraph or two, i'd appreciate your taking the time to enlighten me. :)

    finally, if you were in my shoes at one point and are now a hardened obj c developer who's about to sing the praises of obj c and how easy it is to learn... well, actually, by all means do so. but please address my previous concerns about portability while you're at it.
     
  2. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #2
    Objective-C is a pure superset of C: you can intermix C and Objective-C wherever you wish: you can call C functions etc without issue for Objective-C methods.

    C++ is a little bit different: you need to use Objective-C++. Even that's not particularly difficult. Have fun :)
     
  3. Kingbombs macrumors member

    Joined:
    Jun 24, 2009
    #3
    can you use Objective C++ on iPhone? i didn't think you could
     
  4. kainjow Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #4
  5. moral-hazard macrumors regular

    Joined:
    Jul 27, 2009
    Location:
    Palo Alto, CA
    #5
    As stated...no issue with intermixing Obj-C and C.

    I use low level C code in many instances for writing my own data structures - generally it's helpful to write an objective-C wrapper around whatever C feature you are trying to use (assuming it's simple enough to do so).
     
  6. firewood macrumors 604

    Joined:
    Jul 29, 2003
    Location:
    Silicon Valley
    #6
    Objective C and C are already combined...

    because Objective C is C, a superset thereof, with just a few added forms of macro expansion plus a small runtime to support a little bit of extra punctuation abuse.
     

Share This Page