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.

>
>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().

-Kevin


>--
> / Niklas Brunlid
>Check out Prosit for the TI-89 / TI-92+ at http://prosit.ticalc.org
>Random PQF v5.1 Quote follows:
>
>Have a bit more patience with newbies. Of course some of them act dumb --
>they're often *students*, for heaven's sake.
>        -- (Terry Pratchett, alt.fan.pratchett)
>
>
>




Follow-Ups: