PDA

View Full Version : Bjarne Stoustrup



ygfperson
09-04-2002, 10:14 PM
it's weird how easy it is to contact this guy. you would think the creator of c++ would be too busy for answering e-mail personally.

anyway, here's my email conversation: (sorry for doubting you, dean)

my original message to him:

hello
i've been thinking about the development of c. on a small scale, in mostly
integer programs, the x86 assembly program and its equivalent c program match
each other closely. for instance:

test.c:
int main() {
int x;
x = 1;

return x+3;
}

test.asm:
enter 0,0
xor eax,eax
add eax,3
leave
ret


this is not the best example, but demonstrates the close link of c operators
to assembly commands. other examples:
dest += src; and add dest,src
++dest; and inc dest;

C++ differs from this line of thinking. for instance, the scanf function must
take in variables with reference operators attached to them. the scanf
function then uses that address to return values back. c++ introduces the
ability to use the same variables through other child functions without the
need for reference operators.

void example(int& x);

this makes a potential scanf in c++ more elegant to use, and to create. my
point is that this seemingly easy to implement idea is neglected in C but
added in C++ on the basis of its relationship to the equivalent assembly
language commands.

what do you think? thank you for your time.

--(name withheld from you guys, my name goes here)



his response:


>Delivered-To: bs@research.att.com
>X-Authentication-Warning: mail-red.research.att.com: postfixfilter set sender
to geoschnee2@thetruth.com using -f
>Date: Tue, 03 Sep 2002 00:46:40 -0400
>From: g s <geoschnee2@thetruth.com>
>To: <bs@research.att.com>
>Subject: x86 assembly, c, and c++
>Mime-Version: 1.0
>X-Spam-Status: No, hits=0.0 required=5.0 tests= version=2.20
>X-Spam-Level:
>Content-Transfer-Encoding: 8bit
>X-MIME-Autoconverted: from quoted-printable to 8bit by day.research.att.com id
g834knE01062
>
>hello
>i've been thinking about the development of c. on a small scale, in mostly
>integer programs, the x86 assembly program and its equivalent c program match
>each other closely. for instance:
>
>test.c:
>int main() {
> int x;
> x = 1;
>
> return x+3;
>}
>
>test.asm:
>enter 0,0
>xor eax,eax
>add eax,3
>leave
>ret
>
>
>this is not the best example, but demonstrates the close link of c operators
>to assembly commands. other examples:
>dest += src; and add dest,src
>++dest; and inc dest;
>
>C++ differs from this line of thinking.

Not really. The code generated for individual C++ constructs are as predictable
as that generated from C constructs.


>for instance, the scanf function must
>take in variables with reference operators attached to them. the scanf
>function then uses that address to return values back. c++ introduces the
>ability to use the same variables through other child functions without the
>need for reference operators.
>
>void example(int& x);
>
>this makes a potential scanf in c++ more elegant to use, and to create. my
>point is that this seemingly easy to implement idea is neglected in C but
>added in C++ on the basis of its relationship to the equivalent assembly
>language commands.
>
>what do you think? thank you for your time.

Remember that access through a reference will involve exactly the same machine
operations as access through a pointer for equivalent uses.


>--(name withheld)
>

- Bjarne
Bjarne Stroustrup, http://www.research.att.com/~bs


my response:

>>for instance, the scanf function must
>>take in variables with reference operators attached to them. the scanf
>>function then uses that address to return values back. c++ introduces >the
>>ability to use the same variables through other child functions without
>the
>>need for reference operators.
>>
>>void example(int& x);
>>
>>this makes a potential scanf in c++ more elegant to use, and to create. my
>>point is that this seemingly easy to implement idea is neglected in C but
>>added in C++ on the basis of its relationship to the equivalent assembly
>>language commands.
>>
>>what do you think? thank you for your time.
>
>Remember that access through a reference will involve exactly the same
>machine
>operations as access through a pointer for equivalent uses.

why wasn't this syntax included in standard c? in the development of c++ was
this idea just some additional syntactic sugar, or was it put there for a
greater purpose? (by greater purpose i mean does it contribute to c++'s other
major improvements?)

--(name withheld)


And his response to that:


>Delivered-To: bs@research.att.com
>X-Authentication-Warning: mail-pink.research.att.com: postfixfilter set sender
to geoschnee2@thetruth.com using -f
>Date: Tue, 03 Sep 2002 18:07:54 -0400
>From: g s <geoschnee2@thetruth.com>
>To: Bjarne Stroustrup <bs@research.att.com>
>Subject: Re: [Re: x86 assembly, c, and c++]
>Mime-Version: 1.0
>X-Spam-Status: No, hits=0.0 required=5.0 tests= version=2.20
>X-Spam-Level:
>Content-Transfer-Encoding: 8bit
>X-MIME-Autoconverted: from quoted-printable to 8bit by day.research.att.com id
g841uWE10188
>
>
>>>for instance, the scanf function must
>>>take in variables with reference operators attached to them. the scanf
>>>function then uses that address to return values back. c++ introduces >the
>>>ability to use the same variables through other child functions without
>>the
>>>need for reference operators.
>>>
>>>void example(int& x);
>>>
>>>this makes a potential scanf in c++ more elegant to use, and to create. my
>>>point is that this seemingly easy to implement idea is neglected in C but
>>>added in C++ on the basis of its relationship to the equivalent assembly
>>>language commands.
>>>
>>>what do you think? thank you for your time.
>>
>>Remember that access through a reference will involve exactly the same
>>machine
>>operations as access through a pointer for equivalent uses.
>
>why wasn't this syntax included in standard c? in the development of c++ was
>this idea just some additional syntactic sugar, or was it put there for a
>greater purpose? (by greater purpose i mean does it contribute to c++'s other
>major improvements?)

The key need that led to the introduction of references in C++ was the need to
provide efficient implementation of overloading. If a and b are matrices, you
want a+b to pass pointers/references to a and b to the addition operator - not
copying the large objects, and requiring explicit use of address-of would
distract from conventional notation (i.e. &a+&b is unacceptably ugly).

For more information, see "The Design and Evolution of C++"



>--(name withheld)
>

- Bjarne
Bjarne Stroustrup, http://www.research.att.com/~bs

no-one
09-04-2002, 10:30 PM
>syntactic sugar

i like that one...

he might get paid to answer ?'s there are a number of companies that pay their coders to do this, remember he works/worked for AT&T.

or maybe he's just nice?

Troll_King
09-05-2002, 12:27 AM
I wonder what he thinks about modeling and implimenting an OS in C++. That's what I'm thinking of doing so that I can stop fighting with Microwimps.

mithrandir
09-05-2002, 04:12 AM
Bjarne seems like a really nice chap :)


>>I wonder what he thinks about modeling and implimenting an OS in C++. That's what I'm thinking of doing so that I can stop fighting with Microwimps.<<

He'd probably say you're crazy :p ;) :D

black
09-05-2002, 04:44 AM
the guy acts as God...:)

Troll_King
09-05-2002, 07:29 AM
What would he say about multinational control of satellite communications and the global internet superhighway. Information control as a means to cultural domination....

----------
09-05-2002, 04:33 PM
Interesting, looks like your assembly left out this statement:

x = 1;

ygfperson
09-05-2002, 05:57 PM
doh... i overlooked that.

you would just need to change
xor eax,eax
to
mov eax,1

----------
09-05-2002, 06:22 PM
When I saw this, I kind of figured you were probably playing around with different versions of the code, with x initlialized to 0 in one version.