S
Serve Lau
Tomás Ó hÉilidhe said:I never write recursive functions unless I really really really really
have to. In 95% of cases, you can just use a loop.
tail recursion can always be rewritten to a loop
Tomás Ó hÉilidhe said:I never write recursive functions unless I really really really really
have to. In 95% of cases, you can just use a loop.
It would be interesting tha they AT LAST point out the implementations
of C where there is "NO STACK"... Obviously implementations crippled
beyond recgnition that do not implement recursion do NOT count.
CBFalconer said:There is only one C - that described in the ISO C standard, or its
antecedants. Once the language is extended, it is no longer
portable C.
Chris said:The fact it is not portable is not relevant.
You can write perfectly conforming C that is not portable.
James said:True, but should such code be on-topic here? The US declaration of
independence is conforming C code, because a conforming implementation
of C can, as an extension, accept it after issuing at least one
diagnostic message. I believe that a conforming implementation of C
which accepts all code which has no #error directives that survive
conditional compilation, always producing at least one diagnostic
message, has in fact been created. Should that fact be used as an excuse
for discussing the US revolutionary war in this newsgroup? Where do you
draw the line?
Serve said:I dont think this has been answered yet. I would love to know about a
"stackless" implementation that does support recursion.
James Kuyper said:True, but should such code be on-topic here?
In the starting message of this post I cited Mr Lew PitcherJames said:I believe it has been. The people who are saying that a stack is not
required are not using the word "stack" in the abstract sense of a
generic LIFO allocation mechanism. They are using it in the more
common, more concrete sense of the word, to refer specifically to
implementation of LIFO semantics by use of a single large block of
memory which grows and shrinks only at one end.
Real implementations have been described in this thread that don't
possess such a stack, using activation records which are allocated and
deallocated from locations in memory that are not in any particular
order. I don't see any reason why such an implementation should have any
trouble supporting recursion.
jacob said:James Kuyper wrote: ....
Why do we have to draw lines?
The same people that want strictly on topic messages discuss
British poetry for a week, or the wiring standards
for electrical circuits for a week.
We could discuss extensions to C, POSIX and other things that
concern C directly. comp.std.c is for discussing the standard
language.
Tim Smith said:You could easily design a runtime that doesn't need a stack. The
function call system would work as follows:
1. When a function is called, it is passed a pointer to a block of
memory. This block of memory contains the return address for the call,
and the arguments to the function, and space for the return value. I'll
call this the argument block.
2. The first thing the function does is allocate a block of memory.
This block of memory is large enough to hold all the local variables of
the function, plus enough extra space to hold the largest argument block
the function needs for any calls it makes. I'll call this the
function's local block.
3. When a function returns, it frees its local block.
4. When a function needs to call another function, it fills in the
argument block as needed for the function it wants to call, and calls it.
5. A specific register is assigned for use in passing the pointer to the
argument block to the called function. The machine's equivalent of goto
is used to actually transfer control to the other function. Similarly,
goto is used to return.
Chris said:Yes... Now you want Pure ISO C that is completely portable?
Keith Thompson said:Should comp.unix.programmer be eliminated and merged into comp.lang.*,
since all Unix programming is done in some language?
C is defined by the C standard. That's why it's called the C
standard.
Chris said:The fact it is not portable is not relevant. You can write
perfectly conforming C that is not portable.
There is a difference between topic drift and a post that starts off-topic.jacob navia said:Why do we have to draw lines?
The same people that want strictly on topic messages discuss
British poetry for a week, or the wiring standards
for electrical circuits for a week.
We could discuss extensions to C, POSIX and other things that
concern C directly. comp.std.c is for discussing the standard
language.
jacob navia said:If there is no hardware stack, the implementation does it with a
software stack BECAUSE C NEEDS A STACK.
I think we agree here with the basics. Lets agree then that the
sentence
"There is no stack in C"
is completely wrong.
The sentence:
C needs a stack and if there is no hardware stack it can
be implemented by other means.
is right.
Agreed.
OK?
Malcolm said:.... snip ...
However discussion about who was first to deprecate gotos, which
is topical, could easily lead to a discussion about Ada Lovelace,
which would be acceptable though not topical, becasue the
discussion has naturally led to that point.
jacob navia said:comp.std.c is for discussing the standard language.
Let's say someone is a bit shaky on what static variables are.Keith Thompson said:Someone who says "There is no stack in C" is *clearly* using the word
"stack" in the sense of a hardware stack, not in the sense of a
general LIFO data structure. Such a statement is "completely wrong"
only if you reject the idea that the word "stack" can possibly have
that meaning. And yet posters here very commonly use the unqualified
word "stack" with *exactly* that meaning, particularly when referring
to "*the* stack". I wish they wouldn't, but they do.
James Kuyper said:No, I want this group to concentrate on questions about portable
aspects of the C language,
leaving the non-portable aspects to be discussed by other groups which
are more competent to discuss them. This group has way too many
messages to be easily reviewed. If we could somehow magically remove
the off-topic messages, the complaints about the off-topic messages,
and the complaints about the complaints about off-topic messages, it
would be a much easier group to monitor.
If I want to learn about, for example, Microsoft-specific issues in C
programming, I'll look for a microsoft-specific newsgroup, I don't want
to see it here.
jacob said:In the starting message of this post I cited Mr Lew Pitcher
that started all this:
Repeat after me: "There is no stack in the definition of the C
Language"
Just that. No qualifiers, no "There is a stack that can be
implemented without a machine stack". JUST THAT.
Besides this is nonsense because even if you have a linear
stack it is based on memory pages this days, that are not
contiguous at all and scattered all around in real memory.
That is why I specified: <<The sentence "there is no stack"
is wrong>>
Because they have a stack OBVIOUSLY!
If there is no hardware stack, the implementation does it with a
software stack BECAUSE C NEEDS A STACK.
I think we agree here with the basics. Lets agree then that the
sentence
"There is no stack in C"
is completely wrong.
The sentence:
C needs a stack and if there is no hardware stack it can
be implemented by other means.
is right.
OK?
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.