1,105,427 Community Members

Declaring function

Member Avatar
mattboy64
Newbie Poster
20 posts since Apr 2012
Reputation Points: 13 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

There is a small problem i have
there is a small error that i didnt use to have with the boorland compiler
I'm using xcode these days and in my switch case
im trying to execute a function
(as you can see, the "main" function)

however it says that it is an implicit declaration of function "main"
and that it is invalid in C99

i cant begin to understand this error:(

in boorland i had a few problems but
it still ran
but i dont understand this error

by the way
although the function "main"
is the last function
it shouldnt be a problem as
i had used it in an if statement also before the function "main" was declared.

any help would be crazy awesome :)

Member Avatar
Adak
Posting Virtuoso
1,711 posts since Jun 2008
Reputation Points: 419 [?]
Q&As Helped to Solve: 207 [?]
Skill Endorsements: 10 [?]
 
0
 

main() is always the first function the program will execute - regardless of what order your functions are listed in. (At least, of the functions you can see. There are other functions that boot the program and prepare it's execution, but you never see them)

You MUST have a main() function, explicitly declared, nowadays. (Before this change, some compilers would create a main() for you if you forgot it. No more.)

Your program should have ONE main() function, and your program should NEVER call main(). main() should not call itself, nor should main be called from any other function. (That you can see).

Member Avatar
mattboy64
Newbie Poster
20 posts since Apr 2012
Reputation Points: 13 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

should I make a seperate function IN the main
so that I can execute that function within the switch statement
since main() shouldnt be called

thanks soooo much by the way:)

Member Avatar
deceptikon
Eternally Awesome
4,687 posts since Jan 2012
Reputation Points: 1,341 [?]
Q&As Helped to Solve: 688 [?]
Skill Endorsements: 104 [?]
Administrator
Featured
 
0
 

however it says that it is an implicit declaration of function "main"
and that it is invalid in C99

I'm guessing your main is defined like this:

main()
{
    ...
}

That definition uses a feature called "implicit int", wherein if a type is required such as in the return type of a function, omitting that type will result in the compiler assuming that you meant int. C99 removed that feature entirely, so now you have to explicitly specify the type:

int main()
{
    ...
}
You
This article has been dead for over three months: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: