iOS Weird XCode error - baffled :S

paulbi

macrumors newbie
Original poster
Aug 4, 2010
13
0
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
 

Attachments

paulbi

macrumors newbie
Original poster
Aug 4, 2010
13
0
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
 
Comment

kainjow

Moderator emeritus
Jun 15, 2000
7,958
5
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.
 
Comment

paulbi

macrumors newbie
Original poster
Aug 4, 2010
13
0
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
 
Comment

Luke Redpath

macrumors 6502a
Nov 9, 2007
731
6
Colchester, UK
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.
 
Comment

Cromulent

macrumors 603
Oct 2, 2006
6,039
36
The Land of Hope and Glory
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.
 
Comment
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.