Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

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

  • xcode-screen-grab.jpg
    xcode-screen-grab.jpg
    393.9 KB · Views: 270
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
 
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.
 
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
 
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.
 
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.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.