August Derleth said:
"Vijay Kumar R Zanvar" <
[email protected]> wrote in message
2. What `entry' keyword was used for?
[off-topic]
The entry keyword was intended to provide subroutines with more than
one point of entry. That way, you could write one block of code and
have it `stand in for' different subroutines, because different calls
would deposit you to different places within the code.
In PL/I the ENTRY keyword is used for both multiple entry to procedures, and
also for declaring procedure names. In C the () pretty much identify a
function name so that the entry attribute is not needed. PL/I allows
functions without any argument list, so the ENTRY attribute is needed to
declare them.
The C declaration double sqrt(); in PL/I would be DCL SQRT ENTRY
RETURNS(FLOAT BINARY(53)); though RETURNS implies ENTRY in this case, so
the ENTRY attribute is really only needed when nothing is returned.
The problem with this is obvious: It reduces subroutine calls to
gotos, and it makes it difficult to predict exactly where the next
step of the program would take you. It /could/ be used in structured
code, but only with care. Besides that, it really offers nothing real
subroutines don't.
Like many language features, it can be used for good or evil. The C file
scope variables reduce the need for it. One example in other languages
might be a random number generator and its initialization/seed call.
Another obvious example is the sin() and cos() entries to a routine that can
compute either of them. Multiple entry points are a little more memory and
time efficient in both cases, though faster computers have reduced the
importance of both.
The concept was borrowed from FORTRAN and was part of very early
designs of C. Apparently, some compiler designers did implement it,
but I've never seen an implementation that actually used the entry
keyword.
It is complicated in the case of functions, where different entry points
might have a different return type. When you have multiple entries into a
function, and the entries have a different return type, it greatly
complicates the return statement. In Fortrans that implement ENTRY,
functions return a value by assigning it to a variable named after the
function, so the compiler knows the type to convert it to. (All the names
are EQUIVALENCEd, somewhat similar to C's union, though they are required to
overlap in memory.) PL/I seems to have the ability to convert the type of
the return value to the type of any of the entry points. Possibly the
conversion requirement was enough to remove it from consideration for C.
Really, it isn't a big loss. The concept of one subroutine with
multiple entry points was on its way out even before C was new, and it
was wise of the standards makers to ignore such a half-baked idea.
Another reason it isn't needed so much is the va_arg feature of C. In
languages that have multiple entry points, one use for them is to implement
different argument types or number of arguments. (Consider the atan() and
atan2() functions, though va_arg doesn't help much there.) The small number
of cases where it would be needed can be implemented by having functions
with the required arguments all call a common function. In those cases,
though, I would say that mulitple entries are more readable.
-- glen