This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]