Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: Chinese chess ?

Author: Dieter Buerssner

Date: 18:03:30 07/05/02

Go up one level in this thread


On July 05, 2002 at 15:52:02, Russell Reagan wrote:

>On July 05, 2002 at 10:42:56, Dann Corbit wrote:
>
>>For instance, here is a simple C program to calculate the towers of Hanoi:
>[...]
>>This is the same thing in assembly langauge (generated by the compiler):
>[...]
>
>Why is it that ASM generated from a C++ program is largely unreadable and
>actually larger itself? For example, if I write a simple program, and I name the
>file whatever.c, the compiler compiles it as a C program and the ASM that is
>generated is readable and (if I knew more about ASM) I would be able to tell
>what was going on. If I rename that same program's source file to whatever.cpp,
>the ASM is suddenly littered with a lot of @ signs and underscores and lots of
>other garbage. I don't see why it should be any different for renaming a file
>from .c to .cpp when the source code is exactly the same.

Perhaps, what you are seeing is just the "name mangling". Remember that C++
allows overloading of functions, so that you can have for example

void foo(int);
void foo(long, long);

etc.

So, the C++ compiler must encode the parameters of the functions somehow into
the name - a C-compiler can generate much easier names.

If you use extern "C" void foo(int); (and thereby lose the chache to overload),
you should see, that very similar (if not identical) code will be produced for
the .c and the .cpp file.

BTW. I don't totally agree, that assembler is an easy language to learn. If we
look at the zillion adressing modes available on x86 hardware, at all the formal
restrictions (is a memory operand allowed with this upcode? Is any register
allowed, or just eax, ebx, ecx, edx? ...) I find this much harder to remember
(and therefore to use) than a high level language. Not to mention, that
assembler has no Standard library - so already printing a string on the screen
is not trivial. One could argue, that it is in the library in C only. But the
Standard library belongs to the language. If you start to use x87 assembly with
floating point, many more headaches can start very soon ...

Regards,
Dieter


Regards,
Dieter




This page took 0 seconds to execute

Last modified: Thu, 15 Apr 21 08:11:13 -0700

Current Computer Chess Club Forums at Talkchess. This site by Sean Mintz.