Re: A89: ASM Mentoring


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

Re: A89: ASM Mentoring




> There is no reason that
>
> cout << "Some text.";
>
> should produce any more code than
>
> printf("Some text.");
>
> though I've never tested it. If anything, I believe printf() should produce
> more, assuming the C++ compiler/linker is reasonably well implemented. Why?
> Consider all the different things printf has to know how to deal with:
> strings, chars, int, short, long, float, double, long double, pointers, not
> to mention all the formatting options. Of course this assumes that printf()
> handles all these things by itself, without making any function calls, which
> would be a stupid way to implement it.
>
> The C++ statement makes only one function call, to the
> ostream::operator<<(char *) function, and that function only needs to be
> able to deal with strings. There is no reason that any other ostream
> functions (other than a constructor, which doesn't need to do much) would
> need to be linked. Of course this all depends on the implementation.

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

> The fact of the matter is that most of the claims about C++ being too big
> and too slow are completely unfounded. Yes, it has certain features that can
> slow it down and make the code larger, but it's not necessary to use them.

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 :(

--
 / 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: References: