Re: reading a declaration

From: Gary Labowitz (glabowitz_at_comcast.net)
Date: 12/15/04


Date: Wed, 15 Dec 2004 08:59:22 -0500


"Dave O'Hearn" <daveoh77@pobox.com> wrote in message
news:1103114552.392005.149950@z14g2000cwz.googlegroups.com...
> Mike Wahler wrote:
> > "Dave O'Hearn" <daveoh77@pobox.com> wrote:
<<huge snip>>
> I think this view is most helpful when deciding whether to pass an
> argument by pointer with its address, or by reference.

You got me thinking; isn't a reference more like a #define that has scope?
What I mean is: #define ref x
would do what int &ref = x;
does EXCEPT with define there is no scope or type checking. In other words,
whenever the compiler sees ref, it uses x.
If so, couldn't a compiler implement the references by precompiling them
with the substitution, adding #defines to set and unset the variable and
then
compile as normally? This would be a lot of overhead, of course, but would
it give the same result?

-- 
Gary


Relevant Pages

  • Re: C# equivalent to a smart pointer???
    ... The basic idea is that the compiler may detect ... reference locally, that even if the objGlobal reference is set to null, ... within the same scope if it's not used in any code past a certain point. ... you need to add an explicit reference at the end of the ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: reading a declaration
    ... >> does EXCEPT with define there is no scope or type checking. ... >> whenever the compiler sees ref, ... > If the compiler sees what the reference refers to, ... Yes, that's why I mention that there is a scoping problem, especially with ...
    (comp.lang.cpp)
  • Re: How does "new" work in a loop?
    ... out the whole lexical scope. ... So you mean that the scope of a variable only last one single iteration of the loop? ... Does that mean that the compiler adds code to remove the reference from the fs variable? ... As long as the reference is there, the garbage collector won't collect the object. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: reading a declaration
    ... >> argument by pointer with its address, or by reference. ... > whenever the compiler sees ref, ... If the compiler sees what the reference refers to, ... If it is, the compiler substitutes the ...
    (comp.lang.cpp)
  • Re: Why isnt Dispose() implemented in the compiler?
    ... Going out of scope is a hard call my friend. ... somewhere, that holds a reference, or you could get it back from a function ... To which I pointed out that the using> statement calls Dispose() and foreach uses IEnumerator. ... > So why leave it to developers to screw up when the compiler could> conceivable take care of it for you? ...
    (microsoft.public.dotnet.languages.csharp)