BYTE ARRAY VALUE
-
Hi , Currently doing a project in VC++ (2012) and I have declared a BYTE array i.e BYTE _iDATA[] = { 0x01,0x02,0x03,0x02 }; I pass this variable as a PARAMETER in a function ie BYTE _iDATA[] = { 0x01,0x02,0x03,0x0 }; getRepo(01,iDATA); then the iDATA value as to change, so i create one more new BYTE ARRAY BYTE _cDATA[] = { 0x0A,0xBC,0x03,0xA0 }; getRepo(01,cDATA); I CANNOT USE THE SAME BYTE ARRAY VARIABLE. So if i have to pass 10 diff values to a function, i have to declare 10 byte array variables. How to maintain a single BYTE array variable and reuse it. I tried some conversion method but the function getRepo demands parameter as BYTE[] which cannot be changed due to code restriction from other team. How can i resolve this issue? Thanks Anne void getRepo(unsigned int iNO, BYTE[] userDATA) { }
-
Hi , Currently doing a project in VC++ (2012) and I have declared a BYTE array i.e BYTE _iDATA[] = { 0x01,0x02,0x03,0x02 }; I pass this variable as a PARAMETER in a function ie BYTE _iDATA[] = { 0x01,0x02,0x03,0x0 }; getRepo(01,iDATA); then the iDATA value as to change, so i create one more new BYTE ARRAY BYTE _cDATA[] = { 0x0A,0xBC,0x03,0xA0 }; getRepo(01,cDATA); I CANNOT USE THE SAME BYTE ARRAY VARIABLE. So if i have to pass 10 diff values to a function, i have to declare 10 byte array variables. How to maintain a single BYTE array variable and reuse it. I tried some conversion method but the function getRepo demands parameter as BYTE[] which cannot be changed due to code restriction from other team. How can i resolve this issue? Thanks Anne void getRepo(unsigned int iNO, BYTE[] userDATA) { }
-
Before calling your function just change the values in the array to whatever you need, like:
BYTE myData[] = { 0x01,0x02,0x03,0x0 };
getRepo(1, myData);myData[0] = 0x0A;
myData[1] = 0xBC;
// ... etc
getRepo(1, myData);Veni, vidi, abiit domum
Thank you Richard, it worked .. Since myDATA is of variable size , I created a function for it. I have created a "extern int counter " under a header file (h1.h) the under main.cpp, i include h1.h and also i declare int counter; main() { counter=0; CallFun1(); counter=1; CallFun2(); CallFun3(); } submodule.cpp #include h1.h CallFun2() { if (counter==0) ... else ... } CallFun3() { if (counter==0) ... else ... } Now for CallFun1(), the counter is 1 and once the control goes back to main.cpp, the counter becomes 0 and results in many errors. in main.cpp, once CallFun1() is called, the counter SHOULD be 1 and never change. But here it reverts to old value as 0. Where is the error in my code? Thanks once again....
-
Thank you Richard, it worked .. Since myDATA is of variable size , I created a function for it. I have created a "extern int counter " under a header file (h1.h) the under main.cpp, i include h1.h and also i declare int counter; main() { counter=0; CallFun1(); counter=1; CallFun2(); CallFun3(); } submodule.cpp #include h1.h CallFun2() { if (counter==0) ... else ... } CallFun3() { if (counter==0) ... else ... } Now for CallFun1(), the counter is 1 and once the control goes back to main.cpp, the counter becomes 0 and results in many errors. in main.cpp, once CallFun1() is called, the counter SHOULD be 1 and never change. But here it reverts to old value as 0. Where is the error in my code? Thanks once again....
Firstly please format your code properly by using <pre> tags around it (see the "code" button above the edit box). That makes it so much easier to read as I have done below. Secondly, your design is really not the best way to do it. It is much better to use proper parameters to your functions and control those parameters from the caller, like:
main()
{
counter=0;
CallFun1(counter);
counter=1;
CallFun2(counter);
CallFun3(counter);
}// submodule.cpp
CallFun2(int counter)
{
if (counter==0)
...
else
...
}CallFun3(int counter)
{
if (counter==0)
...
else
...
}Veni, vidi, abiit domum
-
Firstly please format your code properly by using <pre> tags around it (see the "code" button above the edit box). That makes it so much easier to read as I have done below. Secondly, your design is really not the best way to do it. It is much better to use proper parameters to your functions and control those parameters from the caller, like:
main()
{
counter=0;
CallFun1(counter);
counter=1;
CallFun2(counter);
CallFun3(counter);
}// submodule.cpp
CallFun2(int counter)
{
if (counter==0)
...
else
...
}CallFun3(int counter)
{
if (counter==0)
...
else
...
}Veni, vidi, abiit domum