473,406 Members | 2,220 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

static declaration of ‘main’ follows non-static declaration

7
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
Oct 1 '07 #1
7 40507
arnaudk
424 256MB
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
Oct 1 '07 #2
nispe
7
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.
Oct 1 '07 #3
arnaudk
424 256MB
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
Oct 1 '07 #4
nispe
7
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.
Oct 1 '07 #5
arnaudk
424 256MB
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
Oct 1 '07 #6
nispe
7
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.

Expand|Select|Wrap|Line Numbers
  1. int war_game(stack *player_1,stack *player_2,stack *player_1_won,stack *player_2_won)
  2. {
  3.     int i;
  4.     int war_count = 0;
  5.     int winner_found = false;
  6.     card tmp_array_1[DECK_SIZE/2];
  7.     card tmp_array_2[DECK_SIZE/2];
  8.  
  9.     while((((player_1->count>0)||(player_1_won->count>0))&&((player_2->count>0)||(player_2_won->count>0)))&&(winner_found == false))
  10.     {
  11.         war_count++;
  12.         printf("war count = %d\n", war_count);
  13.         for( i = (war_count-1)*WAR_CARDS; i < (war_count * WAR_CARDS); i++)
  14.         {    
  15.             if((player_1->count > 0)&&(player_1_won->count>0))
  16.             {
  17.                 if(player_1->count > 0)
  18.                 {
  19.                     tmp_array_1[i] = pop(player_1);
  20.                 }
  21.                 else
  22.                 {
  23.                     swap_stack(player_1, player_1_won);
  24.                     tmp_array_1[i] = pop(player_1);
  25.                 }
  26.                 }
  27.             if((player_2->count > 0)&&(player_2_won->count>0))
  28.             {
  29.                 if(player_2->count > 0)
  30.                 {
  31.                     tmp_array_2[i] = pop(player_2);
  32.                 }
  33.  
  34.                 else
  35.                 {
  36.                     swap_stack(player_2, player_2_won);
  37.                     tmp_array_2[i] = pop(player_2);
  38.                 }
  39.             }
  40.         }
  41. if(card_compare(tmp_array_1[(WAR_CARDS*war_count)-1],tmp_array_2[(WAR_CARDS*war_count)-1]) == 1)
  42.         {
  43.             for(i = 0; i < (war_count*WAR_CARDS); i++)
  44.             {
  45.                 push(tmp_array_1[i], player_1);
  46.                 push(tmp_array_2[i], player_1);
  47.             }
  48.             winner_found = true;
  49.         }
  50.         else if(card_compare(tmp_array_1[(WAR_CARDS*war_count)-1],tmp_array_2[(WAR_CARDS*war_count)-1]) == 2)
  51.         {
  52.             for(i = 0; i < (war_count*WAR_CARDS); i++)
  53.             {
  54.                 push(tmp_array_1[i], player_2);
  55.                 push(tmp_array_2[i], player_2);
  56.             }
  57.             winner_found = true;
  58.         }
  59.     return war_count;
  60. }
Stack is a user defined ADT

Thanks
Oct 1 '07 #7
nispe
7
Bracket matching from the while loop was the problem... Thanks for the 'comment out code to find the error' technique. Worked wonders.
Oct 1 '07 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

192
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...
4
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...
4
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...
28
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,
12
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....
13
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
11
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...
9
by: mrdarrett | last post by:
typedef struct{ int i, j; } deStruct; deStruct main() { deStruct k; k.i = 0; k.j = 10;
3
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...
1
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...
0
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
1
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...
0
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...
0
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...
0
Oralloy
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,...
0
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...
0
tracyyun
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...
0
agi2029
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,...
0
isladogs
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.