Search code examples
compiler-errorsosx-lionxcode4.5llvm-gccllvm-clang

How resolve error:Conflicting type for "snprintf"


In my app i used Compiler for C/C++/Objective-C is Apple LLVM compiler 4.1 for simulator. For simulator this is working. When i compiling same code for Device i changed Compiler for C/C++/Objective-C is LLVM GCC 4.2. This time i am getting error in stdio.h "Conflicting types for"sprintf" ".

I am using Mac OS x 10.7.4 Xcode 4.5(iOS 6)

This is working fine in (Mac OS x 10.7.4 & Xcode 4.2.3(iOS 5)) && (Mac OS x 10.6.8 & Xcode 3.2.3(iOS 4)).

What is the difference between iOS 5 and iOS 6 for LLVM Compiler. any one please help me?


Solution

  • I see this warning when compiling a Universal App under Mac OS X, when using data types NSInteger or NSUInteger:

    NSInteger thing = 7;
    NSLog(@"Thing is %ld", thing);
    

    This will work under 64-bit, but give warnings under 32-bit (hint; iOS uses 32-bit architecture).

    The (ugly) solution is to force thing to long in this case:

    NSLog(@"Thing is %ld", (long)thing);
    

    Which will work everywhere.

    This is better than:

    #ifdef __x86_64
    NSLog(@"Thing is %ld", thing);
    #else
    NSLog(@"Thing is %d", thing);
    #endif