initialization problem
-
Hi all! I have a problem when i initialize class members. The class is: class NAME { private: int a; int b; BYTE bs1[480]; BYTE bs2[480]; public: // FUNCTIONS NAME(); ~NAME(); } in CPP file: NAME::NAME():a(0),b(0) { memset(bs1, "", sizeof(BYTE)*480) // This run well when debugging memset(bs2, "", sizeof(BYTE)*480) // Here crashes??? } Can anyone tell me why it crashes in the second memset? Thanks!
-
Hi all! I have a problem when i initialize class members. The class is: class NAME { private: int a; int b; BYTE bs1[480]; BYTE bs2[480]; public: // FUNCTIONS NAME(); ~NAME(); } in CPP file: NAME::NAME():a(0),b(0) { memset(bs1, "", sizeof(BYTE)*480) // This run well when debugging memset(bs2, "", sizeof(BYTE)*480) // Here crashes??? } Can anyone tell me why it crashes in the second memset? Thanks!
memset(bs2, **""**, sizeof(BYTE)*480)
why "" ? just change to this :memset(bs2, **0**, sizeof(BYTE)*480)
[VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]
-
Hi all! I have a problem when i initialize class members. The class is: class NAME { private: int a; int b; BYTE bs1[480]; BYTE bs2[480]; public: // FUNCTIONS NAME(); ~NAME(); } in CPP file: NAME::NAME():a(0),b(0) { memset(bs1, "", sizeof(BYTE)*480) // This run well when debugging memset(bs2, "", sizeof(BYTE)*480) // Here crashes??? } Can anyone tell me why it crashes in the second memset? Thanks!
Dennis L wrote:
memset(bs1, "", sizeof(BYTE)*480) // This run well when debugging memset(bs2, "", sizeof(BYTE)*480) // Here crashes???
should be
memset(bs1, '\0', sizeof(bs1));
memset(bs2, '\0', sizeof(bs2));BTW, possibly you should use some symbolic name for the buffer size, for instance
class NAME
{
private:
static const int SIZE = 480;
BYTE bs1[SIZE];
BYTE bs2[SIZE];
//..
}:)
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke -
Dennis L wrote:
memset(bs1, "", sizeof(BYTE)*480) // This run well when debugging memset(bs2, "", sizeof(BYTE)*480) // Here crashes???
should be
memset(bs1, '\0', sizeof(bs1));
memset(bs2, '\0', sizeof(bs2));BTW, possibly you should use some symbolic name for the buffer size, for instance
class NAME
{
private:
static const int SIZE = 480;
BYTE bs1[SIZE];
BYTE bs2[SIZE];
//..
}:)
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke