Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

compile error with function pointer declaration

I'm trying to import openssl to my swift project, but when I add #import "ras.h" in the xxx-Bridging-Header.h, I got the compile error below.

<unknown>:0: error: /Users/wenyun/workspace/newsvn/newios/ios/VanJoyPay2/VanJoyPay2/opensource/OpenSSLRSAWrapper/openssl/include/openssl/rsa.h:100: expected ')'
<unknown>:0: note: /Users/wenyun/workspace/newsvn/newios/ios/VanJoyPay2/VanJoyPay2/opensource/OpenSSLRSAWrapper/o penssl/include/openssl/rsa.h:100: to match this '('

The ras.h:100 is:

int (*rsa_mod_exp)(BIGNUM *r0,const BIGNUM *I,RSA *rsa,BN_CTX *ctx); /* Can be null */

I fixed the error by renaming the const BIGNUM *I to const BIGNUM *i. Does anybody know why the character I is so special?

I did another test today, the result looks so odd. I created a new swift project, wrote 3 header files:

test.h
int test(char *I);

test2.h
#import "test3.h"
#import <Foundation/Foundation.h>

test3.h
int test3();


xxx-Bridging-Header.h
#import "test2.h"
#import "test.h"

I got the compile error again!

finally, removing "#import " makes everything ok.

Why the character "I" could not work together with #import <xxx>?

like image 333
ywen Avatar asked Jun 19 '14 04:06

ywen


1 Answers

The problem is not tied to Swift. It is caused by a previous definition of I in the /usr/include/complex.h file (as Brian Chen guessed it).

Here are the offending lines reported by the compiler:

/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator8.1.sdk/usr/include/complex.h:42:11: note: expanded from macro 'I'
#define I _Complex_I
like image 164
Laurent Etiemble Avatar answered Sep 21 '22 22:09

Laurent Etiemble