Hi,
Im writing a queue based card game using a gcc compiler and Ive begun to get the errors :
war.c: In function ‘war_game’:
war.c:8: warning: ‘main’ is normally a non-static function
war.c:8: error: static declaration of ‘main’ follows non-static declaration
war.h:13: error: previous declaration of ‘main’ was here
where the function main is declared without arguments as below:
int main(void); // on line war.h:13:
and used in war.c as below:
int main(void)
{
...
It seems to me main() isn't declared or used as a static function but the compiler thinks it is.
I would just like some help as to what is causing this if anyone has come across it before.
Thanks,
Sam
7 40507
Don't declare the function main() in your header files or anywhere else! It's a built-in function which represents the entry point of the program, all C/C++ compilers known to mankind already know about main() so use it without declaring it. Have a look at the hello world example for how to make a basic C++ program or google for some other tutorial on C if you prefer that (although I strongly recommend the former).
Arnaud
Thanks for you reply,
Ive removed the main definition from the header and it gets rid of the conflicting definitions but the compiler still thinks that main is static.
war.c: In function ‘war_game’:
war.c:8: warning: ‘main’ is normally a non-static function
It also produces the warning from funtion 'war_game' which is a function called from main and not the otherway round. Im still confused by the nature of this.
Remember the function main() is only to be used once, you can not call at leisure. If it's not too big, please post the code you have so far, especially the part containing the implementation of war_game. (Make sure you enclose your code in [CODE=c] ... [/code] brackets for readability).
Arnaud
main() does only runs when the program executes. The war_game() function is about 90 lines of code and compiles without errors relating to itself but causes the "‘main’ is normally a non-static function" warning when it is included. When the war_game function is commented out the code compiles without and errors or warnings (whether main is declared in the header or not).
I now assume the problem is with the war_game function but the compiler doesn't want to give any hints.
Try to debug war_game(): to home in on what is causing the error, comment out the entire body of the function then uncomment out more and more functionality until you reproduce the error. The error is then caused by the latest block of code to be uncommented. Make sure all { are matched with an }, include semicolons whenever necessary in particular after function calls but not after function definitions. It's hard to give more specific advice since I have no idea what you wrote. What arguments does war_game() take and what should it return? I think you can post your war_game() code here if it's 90 lines, remove empty lines and abridge comments.
Arnaud
Thank you for you persistance...
Here is my code, its a bit of a mess. All user function calls used work and have been tested by other implementations. -
int war_game(stack *player_1,stack *player_2,stack *player_1_won,stack *player_2_won)
-
{
-
int i;
-
int war_count = 0;
-
int winner_found = false;
-
card tmp_array_1[DECK_SIZE/2];
-
card tmp_array_2[DECK_SIZE/2];
-
-
while((((player_1->count>0)||(player_1_won->count>0))&&((player_2->count>0)||(player_2_won->count>0)))&&(winner_found == false))
-
{
-
war_count++;
-
printf("war count = %d\n", war_count);
-
for( i = (war_count-1)*WAR_CARDS; i < (war_count * WAR_CARDS); i++)
-
{
-
if((player_1->count > 0)&&(player_1_won->count>0))
-
{
-
if(player_1->count > 0)
-
{
-
tmp_array_1[i] = pop(player_1);
-
}
-
else
-
{
-
swap_stack(player_1, player_1_won);
-
tmp_array_1[i] = pop(player_1);
-
}
-
}
-
if((player_2->count > 0)&&(player_2_won->count>0))
-
{
-
if(player_2->count > 0)
-
{
-
tmp_array_2[i] = pop(player_2);
-
}
-
-
else
-
{
-
swap_stack(player_2, player_2_won);
-
tmp_array_2[i] = pop(player_2);
-
}
-
}
-
}
-
if(card_compare(tmp_array_1[(WAR_CARDS*war_count)-1],tmp_array_2[(WAR_CARDS*war_count)-1]) == 1)
-
{
-
for(i = 0; i < (war_count*WAR_CARDS); i++)
-
{
-
push(tmp_array_1[i], player_1);
-
push(tmp_array_2[i], player_1);
-
}
-
winner_found = true;
-
}
-
else if(card_compare(tmp_array_1[(WAR_CARDS*war_count)-1],tmp_array_2[(WAR_CARDS*war_count)-1]) == 2)
-
{
-
for(i = 0; i < (war_count*WAR_CARDS); i++)
-
{
-
push(tmp_array_1[i], player_2);
-
push(tmp_array_2[i], player_2);
-
}
-
winner_found = true;
-
}
-
return war_count;
-
}
Stack is a user defined ADT
Thanks
Bracket matching from the while loop was the problem... Thanks for the 'comment out code to find the error' technique. Worked wonders.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Kwan Ting |
last post by:
The_Sage, I see you've gotten yourself a twin asking for program in
comp.lang.c++ .
http://groups.google.co.uk/groups?hl=en&lr=&ie=UTF-8&oe=UTF-8&th=45cd1b289c71c33c&rnum=1
If you the oh so mighty...
|
by: wongjoekmeu |
last post by:
Hello All,
>From a book where I have learned C++ it says that each application must
have at least one
function which is the main() function. Now I have the source code of a
C++ program from...
|
by: Kyle Kolander |
last post by:
I would like one of my template parameters to be an std::string.
I realize this is a non-type and non-integral value.
What options are available to me?
template <class T, string S> // not...
|
by: ravi |
last post by:
Hello everybody,
I am writing a small application which does some work before the user
main function starts execution.
I am trying to #define the main function.
But the problem is that,
|
by: rafalK |
last post by:
Hi All,
I have a big problem with STAThread attribute. I'm using XNA framework
connected with WinForms. XNA is working in non STAThread. I have a
problem with displaying CommonDialog forms e.g....
|
by: axr0284 |
last post by:
Hi,
I have a main function as follows:
int main(void)
{
while(TRUE) { ... }
return TRUE;
}
my question is since the return TRUE is never reached, can I remove
|
by: aarklon |
last post by:
Hi all,
I have heard many discussions among my colleagues that main is a user
defined function or not.
arguments in favour:-
1) if it is built in function it must be defined in some header...
|
by: mrdarrett |
last post by:
typedef struct{
int i, j;
} deStruct;
deStruct main()
{
deStruct k;
k.i = 0;
k.j = 10;
|
by: Mark Hobley |
last post by:
A program typically has a main function defined as follows:
int main (int argc, char *argv) {
/* blah blah */
}
I have noticed that some programs use the syntax:
int main (int argc, char...
|
by: munkee |
last post by:
This is something which is really bugging me, I can see why it happens but not how to fix it.
Basically I have a data acces page with a main form.
This main form then contains a sub form...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |