info-vax@ucbvax.ARPA (02/22/85)
From: nolan%eludom.DEC@decwrl.ARPA (CHRIS 381-2080)
There have been a number of messages recently about a "bug"
in the current VAX C compiler from Digital. Some of the data has
been true, most has been false. Let me try to put the record
straight here.
The issue is of the shape and the position of the argument
block passed to C functions. Under all currently released
versions of VAX C, namely V1.0 through V1.5, the argument block is
a contiguous block of memory on the stack pointed to by the
hardware Argument Pointer, the AP. This is exactly the same as
other Digital VAX Languages. However, VAX C, under these released
versions, is in technical violation of the VAX/VMS Calling
Standard, since doubles and structures are passed by value in the
argument block and that any arguments may be modified by the
compiler generated code. (Note, however, that an exception is
made to the calling standard for C, so that values of length
greater than one longword can be passed in the argument block.)
This becomes a problem if the caller of the C function is a
FORTRAN program, since the C code can modify a permanent argument
block which is supposed to be unmodifyable. Living in a common
language environment as VAX C does, presents some problems that
other stand alone C compilers in other environments do not have to
deal with.
We are currently in field test with VAX C V2.0. In this
development cycle we attempted to correct the above problem and
adhere to the VAX/VMS Calling Standard, at least as far as not
modifying the argument block is concerned. An additional reason
for the change was an attempt to improve the use of registers with
arguments in the called function. Thus we elected to move those
arguments whose address was taken via the & (address-of) operator
onto the stack as an auto variable. This modification was
released to the field in the first field test distribution. We
did not realize at that time how many programs relied on being
able to walk a contiguous block of memory by taking the address of
the first argument and flying from there. It became "painfully"
obvious to us very quickly that this modification was causing our
customers significant problems and was removed in the second field
test distribution two months later. VAX C V2.0 when released to
the field as a product will use the same method of argument
passing as did VAX C V1.n, namely a contiguous block of memory
accessed via the Argument Pointer.
As a future implementation note we reserve the right to
change this method of argument passing in a future release. As of
VAX C V2.0, we will support the VARARGS macro package from
UNIX(*), which provides macros and some run time functions to
permit the walking of a variable argument list. This
functionality is curently part of the ANSI C draft standard and we
will support it future releases of VAX C, starting with V2.0. We
recommend that this be the method of handling variable argument
lists, as this allows us to optimize argument passing to functions
without removing the ability of the programmer to ascertain how
many arguments were passed and to walk the argument list
accordingly.
Chris Nolan,
VAX C Development,
Digital Equipment Corporation.
* UNIX is a trade mark of AT&T Bell Laboratories.