468,103 Members | 1,249 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,103 developers. It's quick & easy.

Ask an old kerword "entry"

Hi all,

It is a history question.

Recently, I read the book "C A reference manual, third edition".
In this book, it list all C language keyword, and one is "entry".
I know it is omitted from ANSCI C, but I hope I can find any data
about it.

Doea any one know how to use it, before?
Thanks

Apr 2 '07 #1
10 3296
On 2 Apr, 10:11, Lung.S...@gmail.com wrote:
Hi all,

It is a history question.

Recently, I read the book "C A reference manual, third edition".
In this book, it list all C language keyword, and one is "entry".
I know it is omitted from ANSCI C, but I hope I can find any data
about it.

Doea any one know how to use it, before?
The original Kernighan and Ritchie book says that it was reserved as a
keyword, but not implemented by any compiler - they don't give any
more detail. They presumably had a feeling that they might need such a
keyword, and some idea what they would use it for, but the need never
actually materialized.

Apr 2 '07 #2
ma**********@pobox.com writes:
On 2 Apr, 10:11, Lung.S...@gmail.com wrote:
>It is a history question.

Recently, I read the book "C A reference manual, third edition".
In this book, it list all C language keyword, and one is "entry".
I know it is omitted from ANSCI C, but I hope I can find any data
about it.

Doea any one know how to use it, before?

The original Kernighan and Ritchie book says that it was reserved as a
keyword, but not implemented by any compiler - they don't give any
more detail. They presumably had a feeling that they might need such a
keyword, and some idea what they would use it for, but the need never
actually materialized.
I think some versions of Fortran have an "entry" keyword, allowing
more than one entry point to be specified for a subroutine. (I don't
know whether this survived into modern Fortran.) For example,
in pseudo-C:

void foo(void)
{
printf("FOO ");
entry bar:
printf("BAR\n");
}

Calling foo() would print "FOO BAR"; calling bar() would print "BAR".
(Presumably there would be some declaration syntax to make the name
"bar" visible to the caller.)

I've seen a more realistic example that combines sin() and cos() into
a single function. Calling it through the primary entry point would
adjust the argument; the remainder of the function, after the
secondary entry point, would compute the sine of the (possibly
adjusted) argument, which happens to be the cosine of the unadjusted
argument.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Apr 2 '07 #3
Keith Thompson wrote:
I think some versions of Fortran have an "entry" keyword, allowing
more than one entry point to be specified for a subroutine. (I don't
know whether this survived into modern Fortran.)
ENTRY is part of modern Fortran (at least through F95). F77 relaxed the
restrictions on its use, making it even more common than F66. The
current syntax has added a RESULT clause that it did not have earlier.

F2C and g77 both compiled a separate copy for each entry, so your
pseudo-C example, if it were the equivalent Fortran,
void foo(void)
{
printf("FOO ");
entry bar:
printf("BAR\n");
}
would be compiled as it it were written
void foo(void)
{
printf("FOO ");
printf("BAR\n");
}
void bar(void)
{
printf("BAR\n");
}
Apr 2 '07 #4
On Apr 2, 8:46 pm, Martin Ambuhl <mamb...@earthlink.netwrote:
Keith Thompson wrote:
would be compiled as it it were written
void foo(void)
{
printf("FOO ");
printf("BAR\n");
}
void bar(void)
{
printf("BAR\n");
}
That's crazy! Why not one function, an extra argument (or global
variable), and an if or switch at the start of the function?

Apr 2 '07 #5
Fr************@googlemail.com writes:
On Apr 2, 8:46 pm, Martin Ambuhl <mamb...@earthlink.netwrote:
>Keith Thompson wrote:
would be compiled as it it were written
void foo(void)
{
printf("FOO ");
printf("BAR\n");
}
void bar(void)
{
printf("BAR\n");
}

That's crazy! Why not one function, an extra argument (or global
variable), and an if or switch at the start of the function?
(There's some context missing here; I didn't write any of the quoted
material.)

The use of the "entry" keyword, assuming the compiler doesn't
duplicate code as described above, allows a small improvement in code
size and speed. You don't have the overhead of passing the extra
argument or of doing a test on entry, and you don't have two copies of
what might be a substantial amount of code. There have been
situations where that might be significant, such as early Fortran
systems, where using Fortran (or any high-level language) was a
sometimes controversial alternative to hand-coded assembly language
(or even machine language).

The functionality that "entry" would provide is something that can be
expressed straightforwardly in assembly language; that's probably why
it was included in Fortran.

The implementation that Martin describes might just have been the
easiest way to implement it, for the purpose of supporting old code
that depended on it (but that, if it's running on modern hardware,
isn't affected by the limitations that existed when it was first
written).

Note, however, that the authors of the C standard apparently agreed
with you (and with me) that it's not worthwhile; the "entry" keyword
was never implemented and did not survive past K&R1.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Apr 2 '07 #6
In article <ln************@nuthaus.mib.org>,
Keith Thompson <ks***@mib.orgwrote:
The functionality that "entry" would provide is something that can be
expressed straightforwardly in assembly language; that's probably why
it was included in Fortran.
....and C--! :)

(See <http://www.cminusminus.org/extern/man2.pdf>, Section 6.7.)
Lauri
Apr 3 '07 #7
Keith Thompson wrote:
ma**********@pobox.com writes:
>On 2 Apr, 10:11, Lung.S...@gmail.com wrote:
>>It is a history question.

Recently, I read the book "C A reference manual, third edition".
In this book, it list all C language keyword, and one is "entry".
I know it is omitted from ANSCI C, but I hope I can find any data
about it.

Doea any one know how to use it, before?
The original Kernighan and Ritchie book says that it was reserved as a
keyword, but not implemented by any compiler - they don't give any
more detail. They presumably had a feeling that they might need such a
keyword, and some idea what they would use it for, but the need never
actually materialized.

I think some versions of Fortran have an "entry" keyword, allowing
more than one entry point to be specified for a subroutine. (I don't
know whether this survived into modern Fortran.) For example,
in pseudo-C:

void foo(void)
{
printf("FOO ");
entry bar:
printf("BAR\n");
}
The 'bar' function here has no prototype. How is it
supposed to handle parameters?

You can use the following, which gives you the same functionality

void foo(void)
{
printf("FOO ";
bar();
}
void bar(void)
{
printf("BAR\n");
}

which should work on all current C compilers, and does
exactly what you are trying to do. And if you later
need to create a "FUU BAR" message, you can just add

void fuu(void)
{
printf("FUU ";
bar();
}

Many compilers can optimize the jump from foo to bar
using a "jump" instead of a "call", automatically
dealing with any parameters passed.
Calling foo() would print "FOO BAR"; calling bar() would print "BAR".
(Presumably there would be some declaration syntax to make the name
"bar" visible to the caller.)

I've seen a more realistic example that combines sin() and cos() into
a single function. Calling it through the primary entry point would
adjust the argument; the remainder of the function, after the
secondary entry point, would compute the sine of the (possibly
adjusted) argument, which happens to be the cosine of the unadjusted
argument.
You can handle it as above, or, you can deal with it
as a #define or an inline function

#define cos(x) = sin((x) + PI/4)

(or whatever the proper transformation is.)

----== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----
May 2 '07 #8
Kevin Handy <kt*@srv.netwrites:
Keith Thompson wrote:
>ma**********@pobox.com writes:
>>On 2 Apr, 10:11, Lung.S...@gmail.com wrote:
It is a history question.

Recently, I read the book "C A reference manual, third edition".
In this book, it list all C language keyword, and one is "entry".
I know it is omitted from ANSCI C, but I hope I can find any data
about it.

Doea any one know how to use it, before?
The original Kernighan and Ritchie book says that it was reserved as a
keyword, but not implemented by any compiler - they don't give any
more detail. They presumably had a feeling that they might need such a
keyword, and some idea what they would use it for, but the need never
actually materialized.
I think some versions of Fortran have an "entry" keyword, allowing
more than one entry point to be specified for a subroutine. (I don't
know whether this survived into modern Fortran.) For example,
in pseudo-C:
void foo(void)
{
printf("FOO ");
entry bar:
printf("BAR\n");
}
The 'bar' function here has no prototype. How is it
supposed to handle parameters?
I don't know. The snippet above, as I said, is pseudo-C, intended to
represent an old Fortran feature that I'm not very familiar with. But
since the "entry" keyword in C died before the ANSI standard was
written, presumably prototypes wouldn't have been required.

But if the feature were to be implemented in C, the obvious semantics
would be that bar() would share the same prototype as foo().
You can use the following, which gives you the same functionality
[snip]
Many compilers can optimize the jump from foo to bar
using a "jump" instead of a "call", automatically
dealing with any parameters passed.
Certainly. The "entry" keyword, as I understand it, was intended to
support a particular micro-optimization, something that's probably
easy to implement in assembly language but difficult to express
directly in C.

[...]
>I've seen a more realistic example that combines sin() and cos() into
a single function. Calling it through the primary entry point would
adjust the argument; the remainder of the function, after the
secondary entry point, would compute the sine of the (possibly
adjusted) argument, which happens to be the cosine of the unadjusted
argument.

You can handle it as above, or, you can deal with it
as a #define or an inline function

#define cos(x) = sin((x) + PI/4)

(or whatever the proper transformation is.)
Yes, the "entry" keyword is unnecessary; that's why it's no longer in
the language. I was merely trying to explain it; I certainly wasn't
advocating it.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
May 2 '07 #9
On Wed, 02 May 2007 13:02:11 -0700, Keith Thompson <ks***@mib.orgwrote:
>Kevin Handy <kt*@srv.netwrites:
>Keith Thompson wrote:
>>ma**********@pobox.com writes:
On 2 Apr, 10:11, Lung.S...@gmail.com wrote:
It is a history question.
>
Recently, I read the book "C A reference manual, third edition".
In this book, it list all C language keyword, and one is "entry".
I know it is omitted from ANSCI C, but I hope I can find any data
about it.
>
Doea any one know how to use it, before?
The original Kernighan and Ritchie book says that it was reserved as a
keyword, but not implemented by any compiler - they don't give any
more detail. They presumably had a feeling that they might need such a
keyword, and some idea what they would use it for, but the need never
actually materialized.
I think some versions of Fortran have an "entry" keyword, allowing
more than one entry point to be specified for a subroutine. (I don't
know whether this survived into modern Fortran.) For example,
in pseudo-C:
void foo(void)
{
printf("FOO ");
entry bar:
printf("BAR\n");
}
The 'bar' function here has no prototype. How is it
supposed to handle parameters?

I don't know. The snippet above, as I said, is pseudo-C, intended to
represent an old Fortran feature that I'm not very familiar with. But
since the "entry" keyword in C died before the ANSI standard was
written, presumably prototypes wouldn't have been required.

But if the feature were to be implemented in C, the obvious semantics
would be that bar() would share the same prototype as foo().
>You can use the following, which gives you the same functionality
[snip]
>Many compilers can optimize the jump from foo to bar
using a "jump" instead of a "call", automatically
dealing with any parameters passed.

Certainly. The "entry" keyword, as I understand it, was intended to
support a particular micro-optimization, something that's probably
easy to implement in assembly language but difficult to express
directly in C.

[...]
>>I've seen a more realistic example that combines sin() and cos() into
a single function. Calling it through the primary entry point would
adjust the argument; the remainder of the function, after the
secondary entry point, would compute the sine of the (possibly
adjusted) argument, which happens to be the cosine of the unadjusted
argument.

You can handle it as above, or, you can deal with it
as a #define or an inline function

#define cos(x) = sin((x) + PI/4)

(or whatever the proper transformation is.)
That, perhaps, is an illustration of the benefits of "entry". The proper
transformation can be encapsulated in the routine body.
>
Yes, the "entry" keyword is unnecessary; that's why it's no longer in
the language. I was merely trying to explain it; I certainly wasn't
advocating it.
It is not so much that it is unnecessary as it is that it inconsistent with
how C is typically implemented. Languages with multiple entry point
routines usually presuppose that the data for a call is in a fixed location
rather than on a stack. The original fortran was like that; recursion was
impossible.

May 2 '07 #10
Keith Thompson <ks***@mib.orgwrote:
But if the feature were to be implemented in C, the obvious semantics
would be that bar() would share the same prototype as foo().
I suppose it's obvious if you've never programmed in Fortran 77.
However - for reference:

http://www.fortran.com/F77_std/rjcnf-15.html#sh-15.7

--
Thomas E. Dickey
http://invisible-island.net
ftp://invisible-island.net
May 3 '07 #11

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

43 posts views Thread by steve | last post: by
reply views Thread by BW | last post: by
5 posts views Thread by Jeff Sandler | last post: by
4 posts views Thread by Jim in Arizona | last post: by
15 posts views Thread by Brady Love | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.