Pelles C forum

C language => Beginner questions => Topic started by: istufkosky on April 14, 2010, 07:47:57 AM

Title: Hello World program error
Post by: istufkosky on April 14, 2010, 07:47:57 AM
I'm trying to make a program from Ivor Horton's "Beginning C" book, and I've been getting this error message. Can anyone help me?

This is the code:

/* Example 1.1 Your Very First C Program - Displaying Hello World */

#include <stdio.h>

void main()
{
   printf("Hello World");
}

This is the error I get when I try to compile the source file:

C:\Users\Ian\Documents\Pelles C Projects\Hello World\Hello.c(6): warning #2181: Incorrect signature for entry-point 'main'; expected 'int __cdecl function(void)' but found 'void __cdecl function(void)'.

I'm very new to C programming, and I don't know that much at all.
Thanks!
~Ian
Title: Re: Hello World program error
Post by: AlexN on April 14, 2010, 08:30:20 AM
Make what the error message says. Change void main() to int main().  ;)
Title: Re: Hello World program error
Post by: istufkosky on April 14, 2010, 05:42:28 PM
OK. What's the main distinction between the void and the int? Why is it such a big difference between them?
Title: Re: Hello World program error
Post by: istufkosky on April 14, 2010, 06:20:49 PM
I did change it, and I got new errors.

POLINK: error: Unresolved external symbol '_WinMain@16'.
POLINK: fatal error: 1 unresolved external(s).


What do these mean?
Title: Re: Hello World program error
Post by: TimoVJL on April 14, 2010, 08:09:57 PM
You have to change subsystem to Console from linker options.

For console program use least this kind of main function
int main(void)
or this
int main(int argc, char **argv)
Title: Re: Hello World program error
Post by: istufkosky on April 15, 2010, 02:46:42 AM
Ok. So I changed to subsystem to console, and I tried the different codes, but it gave me a new error:

Warning #2203: Function 'main' can't be __stdcall, changed to __cdecl.

Thank you for your help so far!
~Ian
Title: Re: Hello World program error
Post by: Stefan Pendl on April 15, 2010, 07:31:18 AM
This is not an error, it is just a warning as you can see, the resulting executable is usually working.
Title: Re: Hello World program error
Post by: AlexN on April 15, 2010, 07:50:02 AM
Quote from: istufkosky on April 14, 2010, 05:42:28 PM
OK. What's the main distinction between the void and the int? Why is it such a big difference between them?
The compiler of Pelles C does a strict type checking and the main-function, witch the startup-code calls, is defined with a return value int.
Title: Re: Hello World program error
Post by: istufkosky on April 15, 2010, 10:35:59 PM
Ah! Thanks so much! It's working now  ;D