Mixing C and Obj-C

Discussion in 'Mac Programming' started by pityme, Aug 4, 2008.

  1. pityme macrumors newbie

    Aug 4, 2008
    Hi all,
    I am confused with the syntax when I write c funciton in Obj-c implementation.
    When I call c function i wrote in the same .m file and compile, it shows a warning saying "implicit function declaration".

    And how could I access those varaibles I defined in the header file for the instance in those c functions?

    Thanks in advance~:p
  2. Cromulent macrumors 603


    Oct 2, 2006
    The Land of Hope and Glory
    Add a function prototype to the header file. Also make sure you have the required C header files included (such as stdio.h for example).

    Same way as you do in a standard C program assuming they are not part of the interface of an Objective-C class.
  3. gnasher729 macrumors P6


    Nov 25, 2005
    Q1: Your function is either purely for use in that one file, or it is for use by everybody. In the first case, make it static, so you avoid problems if you use a function with the same name in another file. In the second case, put a function declaration into the header file, because you wouldn't want to call this function without a function declaration.

    Q2: If you want to access instance variables, why don't you turn the function into a method? You know that you can add private methods to an Objective-C class, don't you? Apart from that, your C function does have a pointer to an object, right? Because accessing instance variables without having an instance doesn't make sense.
  4. pityme thread starter macrumors newbie

    Aug 4, 2008

Share This Page