Re: gcc not compiling

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 10/31/05, Derek Martin <code@xxxxxxxxxxxxxx> wrote:
> On Mon, Oct 31, 2005 at 01:30:44PM -0600, STYMA, ROBERT E (ROBERT) wrote:
> > >     #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
> >
> > In the example, the compiler warning MAY have indicated that
> > it was overriding the void with in.
>
> Perhaps, but I think the better and truer explanation is that it is
> simply impossible for a program not to return some sort of return
> value to the operating system... even if it isn't an intended one.
> Generally the OS will see whatever value is in the appropriate
> register at the end of execution and use that as the exit status,
> whether or not that's what the coder intended.  The behavior isn't
> defined by the standard, as we've said; but practically speaking, I
> don't imagine it's very common to see any different behavior...  ;-)
>
> > Since the original poster was new coder, best that they learn the
> > approved syntax.
>
> I don't disagree, but given that Dotan wrote the most basic form of
> Hello World, I'm assuming he hasn't yet been introduced to the ideas
> of function prototypes, or the C standards.  I've no doubt that he'll
> learn those topics later though.  For the time being, it is probably
> best that he follows the convention of his learning materials.
>
> The trouble is, Brian offered a code correction involving more
> complicated ideas than Dotan will have seen just yet, and then offered
> an explanation for the correction which was patently false.  I think
> if you're going to take the time to correct someone who is trying to
> learn, you should yourself be sure to be correct.
>
> In practice, for simple programs such as "Hello World", the only
> practical reason to adhere to the standard with regard to main()'s
> return value is to avoid compiler warnings.  There's really nothing
> wrong with it, other than that it violates the standard.  But that is
> itself not a crime; there are times when it is quite useful to violate
> the standard, and even necessary, (ironically) to ensure maximum
> portability.  :)
>
> Derek D. Martin
> http://www.pizzashack.org/
> GPG Key ID: 0x81CFE75D
>

Actually, I was trying to one-up the course by being a little prepared
before the professor starts handing out assignments to compile
ourselves. The university website only has Turbo C for download, they
must suppose that everybody uses windows. So I wanted to have a
compiler ready and working before I need it. I pieced that script
together from something that I saw on the web. But you are right- I
will soon learn all the different function types, etc... pray for
me...

Dotan
http://lyricslist.com/lyrics/artist_albums/141/culture_club.php
Culture Club Song Lyrics


[Index of Archives]     [Current Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]     [Fedora Docs]

  Powered by Linux