delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1996/07/09/01:30:00

From: j DOT aldrich6 AT genie DOT com
Message-Id: <199607090524.AA197169843@relay1.geis.com>
Date: Tue, 9 Jul 96 05:01:00 UTC 0000
To: djgpp AT delorie DOT com
Mime-Version: 1.0
Subject: Re: Does DJGPP conform to ANSI

Reply to message 8837894    from J DOT ALDRICH6 AT GE on 07/06/96  5:27PM


>>From my experience on comp.lang.c, you are misreading this.  The paragraph
>>means that if you just fall off the end of main(), without using return
>>or exit(), *then* the return value is undefined.  This is different from
>>the undefined *behaviour* of void main.  The first can make your OS do
>>funny things, the second your program.
>
>I don't follow comp.lang.c, but in my understanding, a function which returns
>a 2- or 4-byte value does so by default in (e)ax, which is where its caller
>would xpect to find such a value.  If a function which ordinarily returned int
>(such as main) were redeclared to return void, then this would not
>necessarily have any effect on the compiler itself.  However, when the void
>function in question returns, any function which expected a return value
>would see whatever happened to be in eax at the time.

I wanted to mention something else in this reply:  Whether a function which
should return a value instead returns void, or a function declared to return
a value returns without a value, the effect from the caller's point of view is
still the same - it is looking for the value of %eax, which contains garbage.
So I cannot see how the two differ in the types of errors they produce; they
should have the same effect.

BTW, this discussion does not necessarily apply to just main().  It is
theoretically possible to define your own versions of any of the libc functions
simply by writing them into your program.  When ld goes to link, it will have
already found the functions it needs, and so won't look in libc.a for them.
Normally, you would be forced to declare your function in accordance with
the header file in which it is declared or receive a compiler error about
redefinition of a function.  However, if you should _fail_ to include the
header file, the compiler wouldn't have anything to compare the function
header to, and thus would cheerfully compile the incorrect version of the
function.  This makes it doubly imperative to include all necessary header
files in your programs, and especially to pay attention to any warnings
about implicit function definitions!

John

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019