info-vax@ucbvax.ARPA (02/22/85)
From: Jerry Leichter <Leichter@YALE.ARPA>
Sorry to post this to the entire list; our host tables are out of date
and apparently can't be updated due to various software problems.
I also apologize to Gail Rubin for posting here private letter here, but
I know of no way to get her permission! :-)
-- Jerry
To: grubin@bbn-spca.ARPA
Subject: Re: DEC C (2.0)
Invalid-addresses: grubin@BBN-SPCA.ARPA (?Invalid domain (host))
Your information about the C standard and portability is reasonable
however, the particular application I am concerned with in my message is
one that is explicitly designed for VMS only. On the VAX, I KNOW what the
stack format is and since I don't use doubles as arguments, the number of
longwords IS the number of arguments.
My application is a package of routines, a run-time library of sorts, that
gets sent to customers and they write programs which call the routines.
Since I then have absolutely no control over whether my routines are called
correctly, or what language they are called from and some of the routines
do have optional arguments, I try to check the number of arguments as one
of my validity checks so I can give a more explicit error code back to the
user program instead of an access violation or strange behavior. I follow
calling standard behavior in that I never modify actual arguments;
basically all arguments are passed by reference or descriptor anyway.
In light of this, the behavior of DEC C 2.0 is
unsuitable for my application. I would be more inclined to stick with
the C I have rather than rewrite my routines in Macro.
-- Gail
What you say is, of course, reasonable. It's a problem to write routines with
variable numbers of arguments in most high-level languages. Some - BASIC is
an example - in fact go so far as to check the number of arguments passed
against the number declared and signal an error if they disagree. I guess in
your case that would be fine, though!
All you need to do is write a single 5-or-so-line MACRO routine that returns
the number of arguments its caller was called with. The routine can get by
with no registers in its register mask - just R0 is plenty for the indirect
refs it will have to do, so calling it will be quite cheap. (Not that a
couple of microseconds is likely to be all that important when you are
already willing to trade overhead for robust routines.)
Actually, I was rather surprised that a quick check of the RTL turned up no
such routine. Oh, well.
-- Jerry
-------