Go Back   Velocity Reviews > Newsgroups > C Programming
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply

C Programming - subroutine stack and C machine model

 
Thread Tools Search this Thread
Old 10-12-2009, 03:13 AM   #1
Default subroutine stack and C machine model


I'm looking and talking about a lot of C that is new to me this
weekend. Does the abstract machine that is described in the standard
have a subroutine stack?

I've heard before that one can imagine things as a stack, and that
wouldn't be wrong, but then again it wouldn't be right. The comment
I'm looking for is not what the standard prohibits in terms of
allegories.

Instead I'm trying to think of what might be useful, given that there
is an execution register, and that it amounts to a stack. Does C have
a function that changes what happens in the execution register?


Frank
  Reply With Quote
Old 10-12-2009, 03:17 AM   #2
Kenny McCormack
 
Posts: n/a
Default Re: subroutine stack and C machine model
In article <8ab64971-735c-48af-8642->,
Frank <> wrote:
>I'm looking and talking about a lot of C that is new to me this
>weekend. Does the abstract machine that is described in the standard
>have a subroutine stack?
>
>I've heard before that one can imagine things as a stack, and that
>wouldn't be wrong, but then again it wouldn't be right. The comment
>I'm looking for is not what the standard prohibits in terms of
>allegories.


If you use the 's-word' in this newsgroup, you will be shunned.

Further, the hyper-literal minded, autistics/Asbergers patient types
here, don't do well with allegories. They are, as I'm sure Kiki will
tell you by and by, best avoided.



Kenny McCormack
  Reply With Quote
Old 10-12-2009, 05:56 AM   #3
Seebs
 
Posts: n/a
Default Re: subroutine stack and C machine model
On 2009-10-12, Frank <> wrote:
> I'm looking and talking about a lot of C that is new to me this
> weekend. Does the abstract machine that is described in the standard
> have a subroutine stack?


I'm not quite sure, but I think the answer is no. Unless I don't
understand what you mean by a subroutine stack, in which case the
answer is probably no.

> Instead I'm trying to think of what might be useful, given that there
> is an execution register, and that it amounts to a stack. Does C have
> a function that changes what happens in the execution register?


I don't think I understand. If you're wondering about breaking the
calling sequence, consider setjmp()/longjmp().

-s
--
Copyright 2009, all wrongs reversed. Peter Seebach / usenet-
http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures
http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated!


Seebs
  Reply With Quote
Old 10-12-2009, 05:59 AM   #4
Seebs
 
Posts: n/a
Default Re: subroutine stack and C machine model
On 2009-10-12, Kenny McCormack <> wrote:
> Further, the hyper-literal minded, autistics/Asbergers patient types
> here, don't do well with allegories.


I am assured by people who apparently give a flying **** that people
treating patients with autism prefer the phrase "people with autism" to
"autistics". The name of the syndrome, BTW, is "Asperger's".

However, it is not necessarily the case that people with various
autism-spectrum traits don't do well with allegories; if anything, many
of them do exceptionally well with allegories, because they are conscious
that the allegory is a tool for thinking about something, not the reality
of the thing described.

>They are, as I'm sure Kiki will
> tell you by and by, best avoided.


Doubtless. Certainly, if I were jealous of people who were much better
at something than I, it would make sense for me to tell other people to
avoid them.

-s
--
Copyright 2009, all wrongs reversed. Peter Seebach / usenet-
http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures
http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated!


Seebs
  Reply With Quote
Old 10-12-2009, 08:02 AM   #5
Stephen Sprunk
 
Posts: n/a
Default Re: subroutine stack and C machine model
Frank wrote:
> I'm looking and talking about a lot of C that is new to me this
> weekend. Does the abstract machine that is described in the standard
> have a subroutine stack?
>
> I've heard before that one can imagine things as a stack, and that
> wouldn't be wrong, but then again it wouldn't be right. The comment
> I'm looking for is not what the standard prohibits in terms of
> allegories.


It may help you to think of nested function calls in terms of an
abstract stack, and many/most implementations actually do use a stack
because that's a logical way to do things*. The Standard does not
require one to exist, though, and even if your implementation does have
one, you'd best not go looking for "the stack" or try to examine it
unless you want your code to be utterly non-portable.

> Instead I'm trying to think of what might be useful, given that there
> is an execution register, and that it amounts to a stack. Does C have
> a function that changes what happens in the execution register?


I have no idea what you mean by "execution register".

S

--
Stephen Sprunk "God does not play dice." --Albert Einstein
CCIE #3723 "God is an inveterate gambler, and He throws the
K5SSS dice at every possible opportunity." --Stephen Hawking


Stephen Sprunk
  Reply With Quote
Old 10-12-2009, 10:24 AM   #6
jacob navia
 
Posts: n/a
Default Re: subroutine stack and C machine model
Frank a écrit :
> I'm looking and talking about a lot of C that is new to me this
> weekend. Does the abstract machine that is described in the standard
> have a subroutine stack?
>

Yes

> I've heard before that one can imagine things as a stack, and that
> wouldn't be wrong, but then again it wouldn't be right.


C assumes a stack, and if the machine has no
stack register it must be implemented in software.

> The comment
> I'm looking for is not what the standard prohibits in terms of
> allegories.
>


The standard doesn't say it explicitely but the structure of
the language assumes a stack.

If main alls initialize, and initialize calls malloc we have
a stack of

main
initialize
malloc

and when malloc finishes, the stack is popped and we are in
initialize. When initialize is finished we pop the stack
and we get into main again.


> Instead I'm trying to think of what might be useful, given that there
> is an execution register, and that it amounts to a stack. Does C have
> a function that changes what happens in the execution register?


It is unclear what you meanby "execution register".


jacob navia
  Reply With Quote
Old 10-12-2009, 10:47 AM   #7
Nick Keighley
 
Posts: n/a
Default Re: subroutine stack and C machine model
On 12 Oct, 05:59, Seebs <usenet-nos...@seebs.net> wrote:
> On 2009-10-12, Kenny McCormack <gaze...@shell.xmission.com> wrote:
>
> > Further, the hyper-literal minded, autistics/Asbergers patient types
> > here, don't do well with allegories.

>
> I am assured by people who apparently give a flying **** that people
> treating patients with autism prefer the phrase "people with autism" to
> "autistics". *The name of the syndrome, BTW, is "Asperger's".
>
> However, it is not necessarily the case that people with various
> autism-spectrum traits don't do well with allegories; if anything, many
> of them do exceptionally well with allegories, because they are conscious
> that the allegory is a tool for thinking about something, not the reality
> of the thing described.


interesting. I come across a lot of people that don't seem to get
allegories and metaphors. They confuse the metaphor with the thing.
What I call abstraction-blindness.

"you can think of electricity as a fluid..."
"is it a fluid?"
"well it can be a usful model, voltage is like..."
"but, is it *really" a fluid?"
"depends what you mean by \"is\""

Is there an an-autistic syndrome?


> > They are, as I'm sure Kiki will
> > tell you by and by, best avoided.

>
> Doubtless. *Certainly, if I were jealous of people who were much better
> at something than I, it would make sense for me to tell other people to
> avoid them.



Nick Keighley
  Reply With Quote
Old 10-12-2009, 11:08 AM   #8
Nick Keighley
 
Posts: n/a
Default Re: subroutine stack and C machine model
On 12 Oct, 03:37, Richard Heathfield <r...@see.sig.invalid> wrote:
> In
> <8ab64971-735c-48af-8642-e79b03faa...@v15g2000prn.googlegroups.com>,


> > The comment
> > I'm looking for is not what the standard prohibits in terms of
> > allegories.

>
> I don't think the C Standard either allows or prohibits any
> allegories. It is strangely silent on the matter.



"O, there's nothing to be hoped for from her! she's as headstrong as
an allegory on the banks of the Nile"


Nick Keighley
  Reply With Quote
Old 10-12-2009, 03:08 PM   #9
Keith Thompson
 
Posts: n/a
Default Re: subroutine stack and C machine model
jacob navia <> writes:
> Frank a écrit :
>> I'm looking and talking about a lot of C that is new to me this
>> weekend. Does the abstract machine that is described in the standard
>> have a subroutine stack?
>>

> Yes
>
>> I've heard before that one can imagine things as a stack, and that
>> wouldn't be wrong, but then again it wouldn't be right.

>
> C assumes a stack, and if the machine has no
> stack register it must be implemented in software.

[...]

To be clear, there must be some stack-like (last-in first-out)
data structure to implement the set of information necessary to keep
track of the currently active set of function calls. This stack can
be implemented in any of a number of ways. A contiguous hardware
stack with a dedicated register pointing to the top is the most
common implementation.

jacob, I presume that's what you meant. I'm not sure what you
mean by "stack register". Obviously there must be some mechanism
to keep track of the top of the stack, and a dedicated hardware
register is a common choice, but it's not required or implied that
it should be a register.

The problem, as we've discussed at great length many times, is that
the phrase "the stack" is often used to refer to a particular kind
of stack implementation, one that's very common but not universal.

It's interesting to note that the C Standard fully describes the
semantics of the language without using the word "stack".

The distinction between a contiguous hardware stack and an abstract
stack (i.e., anything that implements a last-in first-out data
structure) is critical here.

--
Keith Thompson (The_Other_Keith) kst- <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"


Keith Thompson
  Reply With Quote
Old 10-12-2009, 03:38 PM   #10
Chris Dollin
 
Posts: n/a
Default Re: subroutine stack and C machine model
Keith Thompson wrote:

> To be clear, there must be some stack-like (last-in first-out)
> data structure to implement the set of information necessary to keep
> track of the currently active set of function calls.


Nitpick: only if there's some recursion. Otherwise each function can
have its own static area for storing locals & return addresses.

If there's no recursion and no function-pointer variables, the compiler
could "just" inline everything!

--
"The view from where I stand begins to change." - The Reasoning, /Awakening/

Hewlett-Packard Limited registered no:
registered office: Cain Road, Bracknell, Berks RG12 1HN 690597 England



Chris Dollin
  Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
c# programs lieutaryan General Help Related Topics 2 09-24-2009 02:50 AM
LED errors on cisco 3750 stack mike edwards Hardware 0 03-22-2008 09:38 AM




SEO by vBSEO 3.3.2 ©2009, Crawlability, Inc.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46