Re: Intelligent stack?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Bartc

    Re: Intelligent stack?


    <johnywalkyra@p ost.czwrote in message
    news:fc2bf36f-840b-488e-824f-58272ccafd71@p2 5g2000hsf.googl egroups.com...
    Hello,

    I've came across an article at http://www.relisoft.com/Win32/olerant.html
    from which is the citation below:
    >Long, long time ago, when computer languages were still in their infancy,
    >the wizards of C were trying to implement a stack. They
    ....

    However from this excerpt I do not understand how such a stack
    actually works. Could anyone please provide an explanation of the
    stack being described by the author?

    I've no idea about the sort of stack being described. But implemented
    something similar isn't that difficult I don't think. I put together this
    code containing functions push() and pop() that require no housekeeping by
    the caller:

    #include <stdio.h>
    #include <stdlib.h>

    typedef int T; /* Must specify what data type to store */

    typedef struct sstackelem{
    T value;
    struct sstackelem *next;
    } stackelem;

    stackelem *stack=NULL;

    int push(T x) {
    stackelem *new;

    new=malloc(size of(stackelem));
    if (new==NULL) return 0; /* Fail */

    new->value=x;
    new->next=stack;
    stack=new;
    return 1; /* OK */
    }

    T pop(void) {
    T x;
    stackelem *old;

    if (stack==NULL) return 0;
    x=stack->value;
    old=stack;
    stack=stack->next;
    free(old);
    return x;
    }

    int main(void) {
    T x;
    #define marker -1

    if (!push(marker)) exit(0);

    push(100);
    push(200);
    push(300);
    push(400);

    while((x=pop()) !=marker)
    printf("%d\n",x );
    }

    --
    Bartc


  • Richard Tobin

    #2
    Re: Intelligent stack?

    In article <Xye1k.2681$E41 .2388@text.news .virginmedia.co m>,
    Bartc <bc@freeuk.comw rote:
    >However from this excerpt I do not understand how such a stack
    >actually works. Could anyone please provide an explanation of the
    >stack being described by the author?
    No. There isn't any explanation. It's a *joke*. It's meant to
    be ridiculous.

    It seems to be a rather verbose example of the "programmin g koan",
    cf http://catb.org/jargon/html/koans.html#id3141202

    From the context it's supposed to be an obviously-absurd parallel
    with something in OLE, but since I don't know anything about OLE
    I don't get it.

    -- Richard
    --
    In the selection of the two characters immediately succeeding the numeral 9,
    consideration shall be given to their replacement by the graphics 10 and 11 to
    facilitate the adoption of the code in the sterling monetary area. (X3.4-1963)

    Comment

    Working...