Click here to Skip to main content
15,891,431 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,

Our project is build using VC++(MFC) and few files have structures declared, few arrays of integers and char's and they are initialized statically. We have few static member variables initialized with data as below,
C++
char* class::m_psz[] = {
   "COL",
   "FAC",
   "MAS",
   "NOL",
   "SET"
};
 
TYPE_20 class::m_Defaults[] = {
    {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0}
};


And have few typedefs as below,
C++
typedef unsigned char TYPE_20[20];


My requirement is to use Protocol Buffer concept and achieve the above. So How can i write the *.proto file (or the schema) to declare the static array of integers and initialize values to it. And finally i need to generate the *.cs (cshar file) out of it.

Below are my Basic knowladge on PB:
1) I created the classes, used "optional", "repeated" concepts.
2) created the code to declare 2d array.
3) how do I initialize the array at declaration time as it is done in C++?
Below is code of PB schema for 2d array without initialization(at static time)

repeated DefaultsForTYPE_20 m_DefaultsForTYPE_20 = 1;
message DefaultsForTYPE_20{
optional bytes m_DefaultsForTYPE_20 = 1;
}
but how can i initialize it here?

Please provide me your suggestions.

Thanks in Advance.
Posted
Updated 28-Jan-15 21:51pm
v4

1 solution

your TYPE_20 is some memory with a char array of 20 chars. So you access it this way:

C++
void setDefaults( int v)
{
for(int i = 0; i < sizeof(TYPE_20); i++ )
{
m_Defaults[i] = v;//indexed access to the buffer
}
}


It is better to initialize data at runtime by calling such function.

Please read the Pointers Usage in C++ and try some code to better understand the inner conecept of C++. It is worth the time by saving you a lot of headaches. ;-)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900