Share your knowledge at the LQ Wiki.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 01-03-2015, 08:54 PM   #1
Registered: Mar 2014
Posts: 444

Rep: Reputation: Disabled
A C++ compile time error I do not understand.

I have this code:

void main()  {

     printf("\n  Please enter m, n, x and y: "); 
     scanf("%d %d %lf %lf", &M,&N,&X,&Y);     
     printf("  m = %d, n = %d, x = %f, y = %f\n\n", M, N, X, Y);
     printf("   m   n    Re[Pmn(z)]     Im[Pmn(z)]    Re[Pmn'(z)]    Im[Pmn'(z)]\n");
     printf(" -------------------------------------------------------------------\n");  
     for (J=0; J<=M; J++) {
       printf("   %d   %d  %12.6f   %12.6f   %12.6f   %12.6f\n", 
	          J, N, CPM[J][N][0], CPM[J][N][1], CPD[J][N][0], CPD[J][N][1]);
The compilation with g++ gives me a single error:

mclpmn.cpp:250:14: error: ‘::main’ must return ‘int’
void main() {
At Preview time I noticed that the caret ^ moved to the left border. In actual Terminal in Ubuntu it points to between two parentheses:

What kind of integer does the program expect and why?

Sorry for double posting. I don't know how to remove the other one I attached to one of my previous threads. Thanks, - A.
Old 01-03-2015, 09:48 PM   #2
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=14, FreeBSD_10{.0|.1|.2}
Posts: 4,504
Blog Entries: 6

Rep: Reputation: 2421Reputation: 2421Reputation: 2421Reputation: 2421Reputation: 2421Reputation: 2421Reputation: 2421Reputation: 2421Reputation: 2421Reputation: 2421Reputation: 2421
In c++ main() cannot be void - illegal.

void main(){...} /* BAD! */

int main(){...} /* GOOD! */
The main() function must return an integer.

The reason is related to the kernel exit() call implicit in exiting main().

I think that some compilers will allow you write a void main(), but it is actually not allowed by the language.

Last edited by astrogeek; 01-03-2015 at 09:55 PM.
1 members found this post helpful.
Old 01-04-2015, 11:00 AM   #3
Registered: Mar 2014
Posts: 444

Original Poster
Rep: Reputation: Disabled
Thank you, astrogeek. It is not my code. I got it on the web. But I've learned a lesson. -A.
Old 01-04-2015, 11:28 AM   #4
Registered: Mar 2014
Posts: 444

Original Poster
Rep: Reputation: Disabled
Just tried it an it COMPILED!!! Such a simple solution! Thanks.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] INterpretation of Compile time error message in GFortran. AlexBB Linux - Newbie 2 01-03-2015 08:36 PM
[SOLVED] A compile time error in GFortran I don't understand AlexBB Linux - Newbie 16 12-13-2014 11:46 AM
how to understand user time, sys time, wait time, idle time of CPU guixingyi Linux - Server 1 08-24-2010 11:10 AM
rpm compile time error:make error ashmita04 Red Hat 1 07-09-2007 04:44 AM
Trying to Build/Compile for the first time - X error puppy Mandriva 16 09-25-2003 10:26 AM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 02:52 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration