PDA

View Full Version : Weird XCode error - baffled :S




paulbi
Aug 4, 2010, 05:55 AM
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



Cromulent
Aug 4, 2010, 06:14 AM
You haven't declared the function prototypes for those functions, or if they are library functions included the relevant header files.

paulbi
Aug 4, 2010, 06:21 AM
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

kainjow
Aug 4, 2010, 06:26 AM
The compiler doesn't know where that function is at that point, so you need to declare it before the main() function:
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.

paulbi
Aug 4, 2010, 06:33 AM
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

Cromulent
Aug 4, 2010, 07:58 AM
I reordered my methods so that they are now above the "main" method and Voila!! it now works.

This isn't really a fix. Get used to always declaring function prototypes.

Luke Redpath
Aug 4, 2010, 08:00 AM
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.

Luke Redpath
Aug 4, 2010, 08:01 AM
This isn't really a fix. Get used to always declaring function prototypes.

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?

Cromulent
Aug 4, 2010, 01:31 PM
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?

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.