Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Implicit declaration of function "..." is invalid in C99?

I'm trying to declare a function within another function. So here's part of my code: ViewController.m

- (void)updatedisplay{
    [_displayText setText:[NSString stringWithFormat:@"%d", counter]];

}

- (IBAction)minus1:(id)sender {
    counter--;
    updatedisplay();
}

ViewController.h

- (IBAction)minus1:(id)sender;
- (void)updatedisplay;

Which returned me the error of "Implicit declaration of function "..." is invalid in C99".

Result: http://i.imgur.com/rsIt6r2.png

I've found that people have encountered similar problem, but as a newbie I didn't really know what to do next. Thanks for your help! :)

Implicit declaration of function '...' is invalid on C99

like image 329
Rouvis Avatar asked Jul 22 '13 05:07

Rouvis


3 Answers

You are not declaring a function; but a instance method, so to call it you must send it as a message to self;

[self updatedisplay];

EDIT

As @rmaddy pointed out (thanks for that) it is declared as instance method not class method. To make the things clear;

- (return_type)instance_method_name.... is called via 'self' or pointer to object instance.
+ (return_type)class_method_name.... is called directly on the class (static).

like image 121
ludesign Avatar answered Nov 18 '22 20:11

ludesign


Problem

updatedisplay();

solution

[self updatedisplay];

cause

- (void)updatedisplay;

is a class method available for that class.So you have to call from the class to have the method available for you.

like image 7
Lithu T.V Avatar answered Nov 18 '22 19:11

Lithu T.V


That is because you defined your function as a instance method, not a function.

So use it like

- (IBAction)minus1:(id)sender {
    counter--;
    [self updatedisplay]; // Change this line
}
like image 4
βhargavḯ Avatar answered Nov 18 '22 19:11

βhargavḯ