UPT
UPT

Reputation: 1480

Difference in compiling in GCC and LLVM GCC Compiler

I am developing iPhone application which is using the 3 projects. One project is developed with the combination of c and c++ code and one is on Objective C and one is to link both (Objective-C and C and C++ project) the project.

Now when I am compiling my C and C++ project in GCC compiler it compiles perfectly but when I am compiling the same project with LLVM-GCC compiler it's throwing error of 'Initilizer element is not a constant'.

#define MY_WSD const

struct FuncDef {
  i8 nArg;             
  u8 iPrefEnc;         
  u8 needCollSeq;      
  u8 flags;            
  void *pUserData;     
  FuncDef *pNext;      
  char *zName;
  FuncDef *pHash;
};

typedef struct FuncDef FuncDef;

#define FUNCTION(zName, nArg, iArg, bNC, xFunc) \
  {nArg, SQLITE_UTF8, bNC, 0, SQLITE_INT_TO_PTR(iArg), 0, xFunc, 0, 0, #zName}

Here is the code responsible for error:

void myDateTimeFunctions(void){
    static MY_WSD FuncDef aDateTimeFuncs[] = {
    FUNCTION(julianday,        -1, 0, 0, juliandayFunc ), //when I compile the code with LLVM GCC it's giving me error 
                                                          //at this line and the later line and working fine with GCC 
                                                          //alone compiler. But the problem is XCode 4.2 does not come 
                                                          //with GCC alone compiler, so I am unable to run the applciation.
    FUNCTION(date,             -1, 0, 0, dateFunc      ),
  };

Please let me know if I am missing some valuable info for the bug to be fixed.

Upvotes: 1

Views: 385

Answers (3)

UPT
UPT

Reputation: 1480

Hey thanks for your all supports and answer I got the answer of the question. It was the problem with the macro SQLITE_INT_TO_PTR defined in sqlite.c and it was the problem rreported long back with the LLVM_GCC compiler. Actually it is needed to redefine the macro and it will solve the problem.

Here is the reference for the same: http://tribelet.blogspot.com/2008/09/blog-post_08.html language of the post is Japanese but it helped me to get out of the problem.

Upvotes: 0

Per Johansson
Per Johansson

Reputation: 6877

Do you have any warnings before the error? One guess would be that SQLITE_INT_TO_PTR is not defined and defaults to a function call.

Otherwise try llvm-gcc -E on the file (you might have to look in your Xcode build log to get the complete line) to see what it compiles into.

Upvotes: 1

JeremyP
JeremyP

Reputation: 86651

I would guess that SQLITE_INT_TO_PTR(iArg) is non constant when using the LLVM compiler and you therefore have illegal code.

Do you see the same error if you compile with straight gcc using the --std=c99 switch? If you do, try running your gcc-LLVM compile with --std=gnu99 to see if the issue goes away.

Upvotes: 1

Related Questions