ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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);
CLPMN(M,N,X,Y,CPM,CPD);
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]);
}
printf("\n");
}
The compilation with g++ gives me a single error:
Quote:
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:
Quote:
main()
What kind of integer does the program expect and why? Thanks, - A.
You should have started your own thread for this. In any case, the integer main returns is the exit status of the program; generally 0 means success and some other number indicates an error. I suggest picking up a basic C++ programming text book.
I believe the C++ standard says that the return value from main is implementation defined - primarily because Windows doesn't use the return value. UNIX type OS do however, so any program written for UNIX is going to expect a return value from main. The stdlib header provides some macro definitions i.e. EXIT_FAILURE and EXIT_SUCCESS that can be used. It is always correct to return 0 for success.
Code:
#include <cstdlib>
int main (int argc, char** argv) {
if (argc < 2) {
::exit (EXIT_FAILURE);
}
return 0;
}
The main thread must return a value for the system to prcess error messages. 0 is typical, but other values can be deduced. Not too many kernels rely on this.
The answer has been given, but with a ton of side-along comments.
First and foremost, all the compiler is saying is the exact complaint that it wants the TYPE of variable declared for the return of the main() function to be an integer, which is the phrase "int", therefore:
Code:
int main()
That's a first part which you need to correct that complaint.
Then because you've declared a variable type, versus VOID, as the return for the main function, you then need to have a return statement providing an integer value as part of the return. That can be any of:
Code:
return 0;
OR:
Code:
return(0);
OR a non-zero value, which still classifies as an integer. Minus infinity, 0, through plus infinity.
And the secondary stuff are:
You can't use minus infinity or plus infinity, you have to stay within the allowable max range of an integer in your programming environment, also the computer you're using, which is to say that the machine may be 32-bits and therefore whatever the largest negative and positive numbers which can be represented by 32-bits. Those are like plus/minus 2.15 billion, so a lot of numbers. It's safe to just use -1, -2, 0, 1, 2, a few selections, no need to use -9123456 you know?
Some of the discussion there is that if you did not include a "return 0;" statement, the compiler might imply one anyways because it's smarter than you and knows likely what you meant, or that you didn't care enough to give a return or a value, so it adds one for you. Nice, but you don't need to know that level of sophistication and really you should follow the rules as opposed to conveniently skirting them, and learning bad practices at the get go
@btmiller, are you saying that AlexBB is not the Original Poster? What's up with saying they should've started their own thread, I see post #1 where there's a program, the errors, and a question ...
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.