gcc not compiling
Derek Martin
code at pizzashack.org
Mon Oct 31 19:21:23 UTC 2005
On Mon, Oct 31, 2005 at 11:05:41AM -0800, Brian D. McGrew wrote:
> Never protoctype main as a void function or else you can't get a return
> value back to the operating system.
Sure you can:
#include <stdio.h>
void main () {
printf("\nHello World!\n");
}
$ gcc -o foo foo.c
foo.c: In function `main':
foo.c:2: warning: return type of 'main' is not `int'
$ ./foo
Hello World!
[ddm at archonis ~]
$ echo $?
14
As written, the program returns the value of the last expression
executed. In this case, printf() printed 14 characters, and the
program returns that number.
However, it should be noted that this behavior is not defined by the
standard, and can't be depended upon. But if you don't want that, no
problem:
#include <stdio.h>
void main(void)
{
Printf("\nHello World!\n");
exit(0);
}
gcc -o foo foo.c
foo.c: In function `main':
foo.c:2: warning: return type of 'main' is not `int'
[ddm at archonis ~]
$ ./foo
Hello World!
[ddm at archonis ~]
$ echo $?
0
You can return whatever value you like by calling exit().
--
Derek D. Martin
http://www.pizzashack.org/
GPG Key ID: 0x81CFE75D
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
URL: <http://listman.redhat.com/archives/fedora-list/attachments/20051031/e96a6690/attachment-0001.sig>
More information about the fedora-list
mailing list