Hello World program error

Started by istufkosky, April 14, 2010, 07:47:57 AM

Previous topic - Next topic

istufkosky

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

AlexN

Make what the error message says. Change void main() to int main();)
best regards
Alex ;)

istufkosky

OK. What's the main distinction between the void and the int? Why is it such a big difference between them?

istufkosky

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?

TimoVJL

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)
May the source be with you

istufkosky

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

Stefan Pendl

This is not an error, it is just a warning as you can see, the resulting executable is usually working.
---
Stefan

Proud member of the UltraDefrag Development Team

AlexN

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.
best regards
Alex ;)

istufkosky

Ah! Thanks so much! It's working now  ;D