Ask an old kerword "entry"

Discussion in 'C Programming' started by Lung.S.wu@gmail.com, Apr 2, 2007.

  1. Guest

    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, 2007
    #1
    1. Advertising

  2. Guest

    On 2 Apr, 10:11, 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, 2007
    #2
    1. Advertising

  3. writes:
    > On 2 Apr, 10:11, 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) <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"
    Keith Thompson, Apr 2, 2007
    #3
  4. 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");
    }
    Martin Ambuhl, Apr 2, 2007
    #4
  5. Guest

    On Apr 2, 8:46 pm, Martin Ambuhl <> wrote:
    > 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, 2007
    #5
  6. writes:
    > On Apr 2, 8:46 pm, Martin Ambuhl <> wrote:
    >> 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) <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"
    Keith Thompson, Apr 2, 2007
    #6
  7. Lauri Alanko Guest

    In article <>,
    Keith Thompson <> wrote:
    > 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
    Lauri Alanko, Apr 3, 2007
    #7
  8. Kevin Handy Guest

    Keith Thompson wrote:
    > writes:
    >> On 2 Apr, 10:11, 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 =----
    Kevin Handy, May 2, 2007
    #8
  9. Kevin Handy <> writes:
    > Keith Thompson wrote:
    >> writes:
    >>> On 2 Apr, 10:11, 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) <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"
    Keith Thompson, May 2, 2007
    #9
  10. On Wed, 02 May 2007 13:02:11 -0700, Keith Thompson <> wrote:

    >Kevin Handy <> writes:
    >> Keith Thompson wrote:
    >>> writes:
    >>>> On 2 Apr, 10:11, 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.
    Richard Harter, May 2, 2007
    #10
  11. Thomas Dickey, May 3, 2007
    #11
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. AtomicBob
    Replies:
    14
    Views:
    859
    Toby Inkster
    May 2, 2006
  2. Jim Hill
    Replies:
    3
    Views:
    389
    Jim Hill
    Feb 12, 2007
  3. *Prot3anThr3ad*

    old repository for old C++ source code

    *Prot3anThr3ad*, Sep 29, 2006, in forum: C++
    Replies:
    6
    Views:
    365
    *Prot3anThr3ad*
    Oct 2, 2006
  4. Mike Owen

    Allowing entry of a Carriage Return during data entry

    Mike Owen, Jul 27, 2006, in forum: ASP .Net Web Controls
    Replies:
    3
    Views:
    682
    Alessandro Zifiglio
    Jul 27, 2006
  5. Noozer
    Replies:
    2
    Views:
    242
    Dr John Stockton
    Aug 1, 2005
Loading...

Share This Page