ECMA-262-3 in detail. Chapter 8. Evaluation strategy.

  • Thread starter Dmitry A. Soshnikov
  • Start date
J

John G Harris

I checked in MS 2005 compiler. It is so, C++ reference concept *is
just a syntactic sugar* for a pointer. I can statement it now
precisely.

You've proved that in one circumstance a reference parameter can be
implemented using a pointer. Nobody has said it can't be.

It doesn't prove that there is no other way.

Example to check: <URL: http://gist.github.com/380515>

1 C++ source:
2
3 void call_by_reference(int& x)
4 {
5 x = 20;
6 }

Note that the y declared in main is not in scope here.

8 void call_by_pointer(int* x)
9 {
10 *x = 20;
11 }
12
13 void by_value(int x)
14 {
15 x = 20;
16 }
17
18 int _tmain(int argc, _TCHAR* argv[])
19 {
20 int y = 0;
21
22 call_by_reference(y);

y is not in the scope of the body of call_by_reference so the caller
must supply its address because the function body cannot find the
variable in any other way.

23 call_by_pointer(&y);
24 by_value(y);
25
26 return 0;
27 }
28
29 Disassembly:
30
31 The most important lines are 50-51 (by-reference) and 55-56 (by-
pointer)
32 as we see, the same -- load effective address and push to stack.
33
34 int _tmain(int argc, _TCHAR* argv[])
35 {
67 }


P.S.: Also, C++ creator Straustrup also notice that at implementation
level, a reference is just a sugar for the pointer. And this pointer
is dereferenced every time when we deal with a reference operation.

What Stroustrup says in the 3rd edition of his book is this :

"A reference is an alternative name for an object."

and

"In some cases, the compiler can optimize away a reference so that there
is no object representing that reference at run-time."

John
 
D

Dmitry A. Soshnikov

I object to even more misinformation polluting the internet. There's too
much already.

I didn't expect anything else then such cheeky demagogy. And I object
to useless discussions on 10 pages with *irrelevant* nit-picking. You
should learn to talk about the main goal, it is more essential.

Thank you, the talk is over.

Dmitry.
 
J

John G Harris

I didn't expect anything else then such cheeky demagogy. And I object
to useless discussions on 10 pages with *irrelevant* nit-picking. You
should learn to talk about the main goal, it is more essential.

Thank you, the talk is over.

As I suspected, you aren't interested in getting anything right.

John
 

Ask a Question

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.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,132
Latest member
TeresaWcq1
Top