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 589509
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T15:25:53+00:00 2026-05-13T15:25:53+00:00

I was talking with a coworker about this yesterday and it got me thinking

  • 0

I was talking with a coworker about this yesterday and it got me thinking about .Net’s pass by reference.

// C#
class Foo {}

static void Test(ref Foo foo) { ... };
static void Main()
{ 
    Foo f;
    Test(ref foo);
}

Has to be implemented with a double indirection because we’re changing the value of the pointer. Because all reference types are references (pointers)

// C#
static void Test(Foo foo) { ... }
static void Test(ref Foo foo) { ... };

equates to something like

// C++
void Test(Foo *foo);
void Test(Foo **foo);

But if this is a VALUE type, we don’t actually need the double indirection. So I’m curious if

// C#
static void Test(ref int bar) { ... }

becomes

// C++
void Test(int *bar);
// or
void Test(int **bar);

1/29/10 Update:
Reading all the answers, I realize that I was not exactly clear enough in what I wanted and I was misleading by throwing in C++ to what was going on. What I was primarily interested in was how it was implemented in the CLR and what the JIT would do to produce assembly for it. Thanks for all the answers, I found them all to be correct from a perspective but I chose the one that was closest to the question I thought I had asked.

  • 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-13T15:25:54+00:00Added an answer on May 13, 2026 at 3:25 pm

    In C#, when you have a method

    void M(ref int f) { }
    

    and you call it

    int x = 123;
    M(ref int x):
    

    how does this work?

    Logically, this means “x and f refer to the same storage location”.

    The way we actually implement that in the CLR is f is of type “managed reference to variable that can contain an integer”. We pass the managed address of local variable x to M.

    The analog of that in C++ would be a method that takes an &int — a reference to a variable that can contain an int.

    Is that clear?

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

Sidebar

Related Questions

I'm talking about this surprisingly simple implementation of rand() from the C standard: static
What I am talking about is like this website : http://www.ernesthemingwaycollection.com It has a
The documentation is not talking really much about what this technically does. fadeInAnimation.fillMode =
We've been talking about threads in my operating system class a lot lately and
I'am talking about this example of a Scilab<->C wrapper: http://www.scilab.org/doc/intro/node89.html . The strange part
When talking about a generic type, Foo<T> , T is called the generic argument
Talking about XBL is not exactly talking about javascript. So I'll create this question
Assuming that I'm talking about an ASP.NET MVC 3 application, the scenario is something
A coworker and I were talking (after a fashion) about an article I read
Talking about this: http://www.win-rar.com/index.php?id=24&kb_article_id=162 I'm able to calculate the correct CRC of an archive

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.