fscheidl
fscheidl

Reputation: 2301

Conflicting types - Function

The following code leads to "Conflicting types for 'testf'". Does anybody have an idea?

.h:

#import <UIKit/UIKit.h>
@interface RootViewController : UITableViewController {
}
@end

.m:

#import "RootViewController.h"
@implementation RootViewController
- (void)viewDidLoad
{
    [super viewDidLoad];
    NSString *testString=testf(1);
}
NSString* testf(int x){
    NSDateFormatter *dateFormatter=[[NSDateFormatter alloc] init];
    [dateFormatter setDateFormat:@"dd.MM.yyyy"];
    NSString *infstr=[dateFormatter stringFromDate:[[NSDate date] dateByAddingTimeInterval:(60*x)]];
    [dateFormatter release];
    return infstr;
}
- (void)dealloc
{
    [super dealloc];
}
@end

Although this is a stripped down version of my original code, it doesn't work either.

The exact error is "Conflicting types for 'testf'". There are also a couple of warnings, including "Implicit declaration of function 'testf' is invalid in C99".

Thanks in advance.

Upvotes: 1

Views: 6017

Answers (2)

Macmade
Macmade

Reputation: 54000

You need to declare the prototype of your testf function somewhere, before calling it:

NSString* testf(int x);

Either do that in the .h, or in the .m

Upvotes: 8

Stephen Canon
Stephen Canon

Reputation: 106247

You have a declaration of testf (in a header, or earlier in the same file) that does not match the implementation that you listed here.

Upvotes: 1

Related Questions