Extern C Functions in Objective-c

I am developing applications for the iPhone, and after upgrading to sdk 3.0 I get an error message in CFWriteStreamCreateWithFTPURL when binding. This is the code I'm calling to get an error.

streamInfo.writeStream = CFWriteStreamCreateWithFTPURL(NULL, urlRefWrite);

I have an idea that it can be solved using extern "C", but after he entered Google, I did not find a solution to my problem. Any ideas?

Thank you in advance

+3
source share
2 answers

extern "C" can do the trick. I can get the C functions to compile and reference by doing something like this in both the implementation declaration and the header. Here is a simple example:



#if __cplusplus
extern "C" {
#endif

/// converts a degree value to radians
double DegreesToRadians(double degrees);

/// converts radian value to degrees
double RadiansToDegrees(double radians);


#if __cplusplus
}   // Extern C
#endif


Implementation File:


#import "Math.h"

#if __cplusplus
extern "C" {
#endif


double DegreesToRadians(double degrees) {return degrees * M_PI / 180;};
double RadiansToDegrees(double radians) {return radians * 180/M_PI;};


#if __cplusplus
} //Extern C
#endif

+8
source

extern "C" Objective-C. , Objective-C C.

+3

Source: https://habr.com/ru/post/1710390/


All Articles