Allen said:
I wrote many classes. In a class, there is a member variable which is
declared as char szMTreeBuf[4096].
This would imply that each instance of the class has a szMTreeBuff
member (part of relationship). This is valid c++.
On both Windows XP and VxWorks, it
cannot work. Then I try to declare the member variable as static char
szMTreeBuf[4096], it can work again.
Big difference - this would imply that the szMTreeBuff member is shared
between all instances of the class of which the member is a part. Also
valid c++.
But when add some other function
codes, it cannot run normally. I modify the class delearation, and
change szMTreeBuf member variable to be local variable.
Local? (as in not a member anymore...)
Again it can run now.
Why does C++ program run differently on VxWorks?
There are many reasons for this. Do you use the same platform? You
certainly use a different compiler (I'm assuming). I've found that
Windows are more leniant than VxWorks wrt. enforcing hardware traps
when one makes serious mistakes. I must mention that changing where the
buffer is stored in memory has nothing to do with your problem (I
think). This only highlights (in all probability) another problem, as
the memory layout of the program may differ drastically considering the
changes that you've made. I suggest you to induce the problem by
allocating the applicable buffer in a way that induces the problem (as
I understand you, make it part of a class instance - non-static
member): BTW. you may consider getting rid of the horrible sz prefix...
What does is stand for, size? ;-)
class x_c
{
private:
char buff_[1000]; //part of
}
If this now induces the problem, good - leave it that way as it is not
the problem itself. Note that if buff is used as a string, it may
become a problem (as it is not NULL terminated). Also note that when
you copy into buff, to not over-index. You may also use a vector - but
before you do that - stick to one thing - induce the problem and try to
find it - good luck. You seem in over your head.
Werner