Re: A89: ASM Mentoring


[Prev][Next][Index][Thread]

Re: A89: ASM Mentoring




> >I just need to ask: if this is true, then how does the << operator handle
> all
> >the other datatypes you throw at it? Last time I looked, it handles
> _everything_
> >that printf handles - in fact, it handles more, since C++ supports operator
> >overloading.
> >(Yes, I know what you meant with the C++ Statement vs printf(), but see
> below).
> >
>
> There are several different << operators. A different one is used for each
> type (well, some types could feasibly share a single op - short could be
> promoted to int, for example). C++ uses name mangling to implement
> overloaded operators, so that each function ends up with a name that is very
> different from the name it was initially given, and the new name is
> determined by the types of the arguments to the function. At compile time
> the call to ostream::operator<<(char*) would be replaced with a function
> call that has a unique name. So principally, if I only print ints in my
> program, I should only need that one function. But unfortunately this isn't
> what happens in practice, assuming Zeljko is correct about how classes are
> linked.

Yes, I know all this. The point was that all those functions reside in the same
library files, and gcc links the entire file to your program.

> >I've never tested this, but it still feels like C produces smaller code.
> This
> >may be because C++ has larger standard libraries (like Zeljko said), and if
> so
> >it is especially noticalbe with GCC since it links the whole library
> instead of
> >the functions it needs. This is a limitation of the object format IIRC, and
> >can't be changed without re-writing _everything_ associated with GCC and
> making
> >it somewhat incompatible with earlier versions :(
> >
>
> This all just sounds like laziness to me. It seems like such a waste to link
> in things that aren't used. I would guess that C does produce smaller code
> most of the time, because if I write a Hello World program in C it links in
> that huge printf() function, but apparently if I write it in C++ it links in
> every function in the ostream class, which comes out to much more code than
> is in printf().

Isn't printf() also part of a standard library (stdio)? So if you use it you'll
still get all the other functions linked-in... also, printf() itself uses a lot
of other functions IIRC.

Anyway, designing and implementing a compiler suite is no easy task, and the
kind of linking required wouldn't make it easier... seeing as GCC (and the gnu
compiler itself) started out as a small project this kind of stuff probably
wasn't a high priority. And implementing it now would be kinda hard, especially
if they want to keep it backwards-compatible.

<OFF-TOPIC>
As a new user to Google I just had to point out their current logo =)
</OFF-TOPIC>

--
 / Niklas Brunlid
Check out Prosit for the TI-89 / TI-92+ at http://prosit.ticalc.org
Random PQF v5.1 Quote follows:

The Librarian had seen many weird things in his time, but that had to be
the 57th strangest. [footnote: he had a tidy mind]
        -- (Terry Pratchett, Moving Pictures)





References: