[gnu.gcc.bug] VMS 5.1/GCC 1.35 return value bug

BAIHELP%TAMSTAR.BITNET@MITVMA.MIT.EDU (07/20/89)

Well --

    Having read the letter from Chris Siebenmann about how Unix normally
    ignores a return value if one is not supplied, I still has a problem.

    Isn't it the same thing to want to return a "all ok" signal to the
    operating system if no other value is supplied (ie. exit(-1);).
    I assume that Unix does return "some kind" of value if one is not
    supplied.  This is what VMS is expecting.  If you don't exit in a
    particular way (ie. exit(-1);) then VAX C assumes everything went ok,
    puts a 1 in r0 and returns.

    Where should the code be modified to cause a return from main to be
    different from a return from any other routine, in that a assumed
    return value of 1 is supplied in r0.

                                       Bryan A. Ignatow
                                       VMS Software Specialist
                                       Public Domain Software Specialist
                                       Academic Vax Cluster
                                       Texas A&M Univeristy
                                       Bitnet: BAIHELP@TAMVENUS
                                       Internet: BAIHELP@venus.tamu.edu

BAIHELP%TAMSTAR.BITNET@MITVMA.MIT.EDU (07/21/89)

   In reference to the problem of VMS 5.1 needing a longword 1 in r0 if
   no other value is supplied:

       o Unix lets you drop out of the bottom of main.
       o Microsoft C lets you drop out of the bottom of main.
       o From "The C Programming Language" by K&R pg. 26

           A function need not return a value; a RETURN statement
           with no expression causes control, but no useful value,
           to be returned to the caller, as does "falling off the
           end" of a function by reaching the terminating right
           brace.  And the calling function can ignore a value
           returned by a function.
           ... Since MAIN is a function like any other, it may
           return a value to its caller, which is in effect the
           environment in which the program was executed.
           ... we have omitted RETURN statements from our MAIN
           functions up to this point, but we will include them
           hereafter, as a reminder that PROGRAMS SHOULD RETURN
           STATUS TO THEIR ENVIRONMENT.

   Hence, since I won't get into an arguement about "good programming
   style", I will say that the problem lies not with the VAX C compiler
   but with the operating system.  VMS expects a status return value in
   general purpose register 0 and if not supplied retruns an error the
   the process running the program.  Now if "in the interests of good
   style" a programmer would use exit(n); to halt his program on error,
   then sould we not assume that if a program is about to drop off the
   end of main and hasn't set a prefered return value that one may be
   assumed for it.  This allows COMPATIBILITY with the VMS 5.1 operating
   system.

   I am not suggesting this change be made for all implementations of
   GCC, only for those running under VMS which need it.

                                       Bryan A. Ignatow
                                       VMS Software Specialist
                                       Public Domain Software Specialist
                                       Academic Vax Systems
                                       Texas A&M University
                                       Bitnet: BAIHELP@TAMVENUS
                                       Internet: BAIHELP@venus.tamu.edu

rms@mipos3.intel.com (07/21/89)

I would not mind installing changes for main to return 1 by default on VMS,
if somebody else implements them cleanly.

msnyder@tut.cis.ohio-state.edu (Michael V Snyder) (08/02/89)

Brian and other VMS-using friends:
    Instead of trying to make the compiler recognise main() as a
special case, would it not be easier to make EVERY function return
a 1 in R0 in case an explicit return is not performed?  I don't think
this behavior should cause problems, as the behavior under these
circumstances is undefined.  Any program that depends on a function
returning the value of it's last expression, say, probably shouldn't.

				Michael Snyder
				msnyder@csi.compuserve.com