This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Bad inlining because of "throw"
- From: Luca Béla Palkovics <luca dot bela dot palkovics at gmail dot com>
- To: gcc-help at gcc dot gnu dot org
- Date: Wed, 10 Nov 2010 11:55:17 +0100
- Subject: Bad inlining because of "throw"
Dear everyone,
Every than and now I check the asm of my projects.. and found out.
That g++(4.4.5) likes to inline my throw classes, which is pretty bad
for me. I believe a throw is something that happens when something is
wrong (so at normal usage there wont be a throw) therefore should never
get inlined ..
The code I have:
void CHandleMove::onMove(const char *packet, unsigned size)
{
....
CMove move(packet, size);
....
}
CMove::CMove(const char* packet, unsigned size):
packetStruct(reinterpret_cast<const SMove*>(packet))
{
if(size != sizeof(SMove))
{
throw CException(WRONG_SIZE,"Packet size is different from
structure");
}
}
Now at this simple code .. I would think that CMove::CMove(..) gets
inlined into CHandleMove::onMove(..) but g++ does inline the
CExpection::CExpection(..) into CMove::CMove(..) and therfore (i think)
doesn't inline the CMove::CMove..().
When I change the function to something like this:
void throwPacketWrongSize()
{
throw CException(WRONG_SIZE,"Packet size is different from structure");
}
CMove::CMove(const char* packet, unsigned size):
packetStruct(reinterpret_cast<const SMove*>(packet))
{
if(size != sizeof(SMove))
{
throwPacketWrongSize();
}
}
Than it does what I would like to have..
throwPacketWrongSize(..) doesn't get inlined into CMove::CMove(..) and
CMove::CMove(..) gets inlined into CHandleMove::onMove(..)
Is there are way to tell g++ "DON'T INLINE THIS" or something like
this ? Or is it a bug that it inlines my CException::CException ?
I am using g++ (Ubuntu/Linaro 4.4.4-14ubuntu5) 4.4.5 on a 64Bit system
with C++0x and the -O2 option.
Thanks in advance.
Luca BÃla Palkovics