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

pityme

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

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

Thanks in advance~:p
 

Cromulent

macrumors 604
Oct 2, 2006
6,816
1,101
The Land of Hope and Glory
Hi all,
I am confused with the syntax when I write c funciton in Obj-c implementation.
Q1:
When I call c function i wrote in the same .m file and compile, it shows a warning saying "implicit function declaration".

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

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

Thanks in advance~:p

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

gnasher729

Suspended
Nov 25, 2005
17,980
5,566
Hi all,
I am confused with the syntax when I write c funciton in Obj-c implementation.
Q1:
When I call c function i wrote in the same .m file and compile, it shows a warning saying "implicit function declaration".

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

Thanks in advance~:p

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.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.