Re: #define bug in gcc for delta builds?
Re: #define bug in gcc for delta builds?
- Subject: Re: #define bug in gcc for delta builds?
- From: Stephen Northcott <email@hidden>
- Date: Wed, 4 Feb 2009 19:57:25 +0700
Hi Matt,
Ahh, Now I see (as I recently fixed a similar issue here)
What I think you have is this:
class Foo
{
Foo();
void SomeMethods();
....
private:
int mVar1;
#ifdef BAD_Whatever
int mVar2;
#endif
int mVar3;
};
Something like that. Yes.
In Foo.cpp you define BAD_Whatever so as far as any code in their is
concerned your class has 12 bytes of member variables.
Except that BAD_Whatever is defined in the header file, not the .cpp
file.
But in bar.cpp, where you don't define BAD_Whatever, you do
something like this:
I am assuming you meant .h in the line above this?
But AFAIK BAD_Whatever being defined in the header and included in
the .cpp means it's value should carry over.
Foo* newFoo = new Foo;
At this point, the compiler thinks that it only needs to allocate 8
bytes for the Foo (as that is how large the class is as seen in
bar.cpp) so you object ends up being smaller than the Foo class
thinks it is. Any attempt to access mVar3 inside foo's code will
result in it writing to un-alloced memory.
In a nutshell, when you do new (or allocate an object on the stack),
the class itself is NOT responsible for ensuring the correct omount
of memory is reserved, it is the compiler that does.
(If you were to allocate any Foos within Foo.cpp itself then they
would be the 'correct' size.
This sounds very like the problem I am seeing.
I still don't understand how the compiler can get this wrong though if
it used the header file, because the header file and the #defines will
tell it exactly how much space is required.
But thanks for sharing that. It certainly makes sense, even if
your .ccp / ,h bits were a little confusing.
Kind regards,
Stephen.
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden