OT Rant on why C++ Sucks (Was Re: strict aliasing: how to swap pointers)

Rupert Wood me@rupey.net
Wed Apr 30 10:21:00 GMT 2008


me22 wrote:

> <begin tags do not contain slashes>
>
> Not turning on inlining? What a great idea! It's obviously better to
> do a function call for a tiny little operation than to just inline the
> code.  Why, that way the functions even show up!  That must be better
> than stripping it from the binary since it's never called.  Who needs
> strong static type safety, anyways?
>
> </end tag>

I agree, code like this should probably get inlined (or at least be available to the optimizer to inline if it wants) but even if it's not the compiler doesn't actually need to instantiate a new exchange method for every type.

All pointers are the same size (modulo funny platforms) and copying a pointer is the same operation regardless of what it points to (modulo smart pointers). So the actual exchange operation is always the same, so the assembly generated for all instances of this method will be the same, and so the compiler only need emit one copy of exchange and reuse it for all calls. Even if exchange operated opaquely on types and structures rather than pointers it would only need one instance for types sizeof == 4, one for types sizeof == 8 etc.

Rup.




More information about the Gcc-help mailing list