NO

Author Topic: Hello World program error  (Read 5867 times)

istufkosky

  • Guest
Hello World program error
« 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

Offline AlexN

  • Global Moderator
  • Member
  • *****
  • Posts: 394
    • Alex's Link Sammlung
Re: Hello World program error
« Reply #1 on: April 14, 2010, 08:30:20 AM »
Make what the error message says. Change void main() to int main();)
best regards
 Alex ;)

istufkosky

  • Guest
Re: Hello World program error
« Reply #2 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?

istufkosky

  • Guest
Re: Hello World program error
« Reply #3 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?

Offline TimoVJL

  • Global Moderator
  • Member
  • *****
  • Posts: 2115
Re: Hello World program error
« Reply #4 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
Code: [Select]
int main(void)or this
Code: [Select]
int main(int argc, char **argv)
May the source be with you

istufkosky

  • Guest
Re: Hello World program error
« Reply #5 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

Offline Stefan Pendl

  • Global Moderator
  • Member
  • *****
  • Posts: 582
    • Homepage
Re: Hello World program error
« Reply #6 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.
---
Stefan

Proud member of the UltraDefrag Development Team

Offline AlexN

  • Global Moderator
  • Member
  • *****
  • Posts: 394
    • Alex's Link Sammlung
Re: Hello World program error
« Reply #7 on: April 15, 2010, 07:50:02 AM »
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

  • Guest
Re: Hello World program error
« Reply #8 on: April 15, 2010, 10:35:59 PM »
Ah! Thanks so much! It's working now  ;D