Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6104249
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T13:49:14+00:00 2026-05-23T13:49:14+00:00

In a previous question ( Get object call hierarchy ), I got this interesting

  • 0

In a previous question (Get object call hierarchy), I got this interesting answer:

The call stack is not there to tell you where you came from. It is to tell you where you are going next.

As far as I know, when arriving at a function call, a program generally does the following:

  1. In calling code:

    • store return address (on the call stack)
    • save registers’ states (on the call stack)
    • write parameters that will be passed to function (on the call stack or in registers)
    • jump to target function
  2. In called target code:

    • Retrieve stored variables (if needed)
  3. Return process: Undo what we did when we called the function, i.e. unroll/pop the call stack:

    • remove local variables from the call stack
    • remove function variables from the call stack
    • restore registers state (the one we stored before)
    • jump to return address (the one we stored before)

Question:

How can this be viewed as something that “tells you where you are going next” rather than “tell you where you came from”?

Is there something in C#’s JIT or C#’s runtime environment that makes that call stack work differently?

Thanks for any pointers to documentation about this description of a call stack — there’s plenty of documentation about how a traditional call stack works.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T13:49:14+00:00Added an answer on May 23, 2026 at 1:49 pm

    You’ve explained it yourself. The “return address” by definition tells you where you are going next.

    There is no requirement whatsoever that the return address that is put on the stack is an address inside the method that called the method you’re in now. It typically is, which sure makes it easier to debug. But there is not a requirement that the return address be an address inside the caller. The optimizer is permitted to — and sometimes does — muck with the return address if doing so makes the program faster (or smaller, or whatever it is optimizing for) without changing its meaning.

    The purpose of the stack is to make sure that when this subroutine finishes, it’s continuation — what happens next — is correct. The purpose of the stack is not to tell you where you came from. That it usually does so is a happy accident.

    Moreover: the stack is just an implementation detail of the concepts of continuation and activation. There is no requirement that both concepts be implemented by the same stack; there could be two stacks, one for activations (local variables) and one for continuation (return addresses). Such architectures are obviously much more resistant to stack smashing attacks by malware because the return address is nowhere near the data.

    More interestingly, there is no requirement that there be any stack at all! We use call stacks to implement continuation because they are convenient for the kind of programming we typically do: subroutine-based synchronous calls. We could choose to implement C# as a “Continuation Passing Style” language, where the continuation is actually reified as an object on the heap, not as a bunch of bytes pushed on a million byte system stack. That object is then passed around from method to method, none of which use any stack. (Activations are then reified by breaking each method up into possibly many delegates, each of which is associated with an activation object.)

    In continuation passing style there simply is no stack, and no way at all to tell where you came from; the continuation object does not have that information. It only knows where you are going next.

    This might seem to be a highfalutin theoretical mumbo jumbo, but we essentially are making C# and VB into continuation passing style languages in the next version; the coming “async” feature is just continuation passing style in a thin disguise. In the next version, if you use the async feature you will essentially be giving up stack-based programming; there will be no way to look at the call stack and know how you got here, because the stack will frequently be empty.

    Continuations reified as something other than a call stack is a hard idea for a lot of people to get their minds around; it certainly was for me. But once you get it, it just clicks and makes perfect sense. For a gentle introduction, here are a number of articles I’ve written on the subject:

    An introduction to CPS, with examples in JScript:

    http://blogs.msdn.com/b/ericlippert/archive/2005/08/08/recursion-part-four-continuation-passing-style.aspx

    http://blogs.msdn.com/b/ericlippert/archive/2005/08/11/recursion-part-five-more-on-cps.aspx

    http://blogs.msdn.com/b/ericlippert/archive/2005/08/15/recursion-part-six-making-cps-work.aspx

    Here are a dozen articles that start by doing a deeper dive into CPS, and then explain how this all works with the coming “async” feature. Start from the bottom:

    http://blogs.msdn.com/b/ericlippert/archive/tags/async/

    Languages that support continuation passing style often have a magic control flow primitive called “call with current continuation”, or “call/cc” for short. In this stackoverflow question, I explain the trivial difference between “await” and “call/cc”:

    How could the new async feature in c# 5.0 be implemented with call/cc?

    To get your hands on the official “documentation” (a bunch of white papers), and a preview release of C# and VB’s new “async await” feature, plus a forum for support Q&A, go to:

    http://msdn.com/vstudio/async

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I had a previous question that touched this topic ( Rails: how to get
After getting fine answer to my previous question , I came across another problem.
Ok, so - this is heavily related to my previous question Transforming an object
This is a followup to my previous question , which got solved (thank you
I hoped the answer to my previous question whould help me with this one,
This is related to my previous question but it is a different problem. I
I am trying to get meta-data of all built-in Clojure functions. In previous question
Following my previous question: Lambda expression to access a property of an object that
This question is a follow up to my previous question about getting the HTML
This follows on from my previous question about Moose structured types. I apologise for

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.