error: expected initializer before "int"

Member
Posts: 75
Joined: 2009.01
Post: #1
I'm following the OpenGL SuperBible 4th edition.
I'm using Xcode and created a project in foundation tools, c++.
I've written some simple code but I get an error: expected initializer before "int" when i try to compile and since i'm new to this, I can't figure out what the problem is.

Here's a snippet of the code:
void main(void)
int main(int argc, char * const argv[]);
X error: expected initializer before "int"

help =X
Quote this message in a reply
Member
Posts: 245
Joined: 2005.11
Post: #2
You've declared main() twice. Remove the "void main(void)".
You also shouldn't be declaring a prototype for main(), which is what this appears to be since there's a semicolon at the end of the second one. When you do put a main function in your code, the second prototype is correct. Like this:
Code:
int main(int argc, char **argv)
{
//your code here
}
By the way, when you want to paste code hit the "#" button above the message field to enter CODE tags.
Quote this message in a reply
Member
Posts: 75
Joined: 2009.01
Post: #3
oh, i didnt mean to put the semicolon.

Code:
int main(int argc, char * const argc[])
{
// code
}

The book i'm reading has the void main(void) right above this code.
When i get rid of one (void main(void)) it still gets an error.
Quote this message in a reply
Member
Posts: 245
Joined: 2005.11
Post: #4
Quote:error: expected initializer before "int"
This suggests something is wrong before the "int". Look at the lines above. If there isn't any code above in the C file, look at the headers you've included - a typo in a file you wrote could cause this. Alternatively, including a C++ or Objective-C header in a C file (for example) will confuse the compiler, although in that instance I'd expect loads of errors.
If you still can't work it out, paste the whole file into this thread.
Quote this message in a reply
Post Reply