Weird XCode error - baffled :S

Discussion in 'iPhone/iPad Programming' started by paulbi, Aug 4, 2010.

  1. macrumors newbie

    Joined:
    Aug 4, 2010
    #1
    Hi Guys,

    Well this is my first post and unfortunately I really wanted it to be a positive one but alas it isn't.

    After programming for a number of years on Windows PC platforms I've decided to start working on an iPhone & iPad game partly because I believe I've got a REALLY good idea :D

    But I first need to get up to speed with Objective-C, which actually doesn't look to bad, just a little different from my usual day to day stuff.

    However while working through a command line book example I've hit a problem that I cannot resolve or figure out.

    The problem seems to be - no functions can be called without getting the error "Conflicting types for FUNCTION_NAME".

    I've attached a screen shot that I hope helps.

    Bloody weird and if anyone can help me then I will be VERY grateful indeed.

    Thanks,
    Paul
     

    Attached Files:

  2. macrumors 603

    Cromulent

    Joined:
    Oct 2, 2006
    Location:
    The Land of Hope and Glory
    #2
    You haven't declared the function prototypes for those functions, or if they are library functions included the relevant header files.
     
  3. thread starter macrumors newbie

    Joined:
    Aug 4, 2010
    #3
    So do I have to create a new header file for cmdLineTest.m called cmdLineTest.h and import it?


    Edited to say that - in the book tutorial there is no mention of a header file or any definitions for the new methods
     
  4. Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #4
    The compiler doesn't know where that function is at that point, so you need to declare it before the main() function:
    Code:
    void someFunction();
    You could use a header but for this example it's unnecessary.

    BTW this is a C issue, not Obj-C, although you can run into the same issue with methods once you get into classes.
     
  5. thread starter macrumors newbie

    Joined:
    Aug 4, 2010
    #5
    Thanks for the quick replies guys - I really appreciate it.

    kainjow,
    I reordered my methods so that they are now above the "main" method and Voila!! it now works.

    Up until now all the examples I've played with have had header files so I wasn't aware of this 'feature' :D

    I guess this is what makes learning fun :D:D

    Thanks very much both of you.

    Cheers,
    Paul
     
  6. macrumors 603

    Cromulent

    Joined:
    Oct 2, 2006
    Location:
    The Land of Hope and Glory
    #6
    This isn't really a fix. Get used to always declaring function prototypes.
     
  7. macrumors 6502a

    Joined:
    Nov 9, 2007
    #7
    The solution has already been posted but to help you understand further the "conflicting types" error message, when you reference a function that hasn't already been previous declared, the compiler has to make a guess at what it does (hence the warning, "implicit declaration of function").

    I believe the compiler assumes implicit functions to return type int, so when you declare your functions later in the file with a different return type to int, that is why you get the conflicting types error.
     
  8. macrumors 6502a

    Joined:
    Nov 9, 2007
    #8
    Is it really such a big deal to simply declare functions at the top of the file if they are internal/private to that file?
     
  9. macrumors 603

    Cromulent

    Joined:
    Oct 2, 2006
    Location:
    The Land of Hope and Glory
    #9
    Sure, but if they are internal / private to the file they should be declared as static functions.

    Still it is worth using function prototypes rather than relying on the order of the functions because that is going to cause problems down the road when you insert some code and it doesn't work.
     

Share This Page