Answer the question
In order to leave comments, you need to log in
I came across a strange structure declaration - where can I read about this?
Here's a code snippet:
struct t_EEPROMOffsets
{
t_EEPROMOffsets(bool isEKM)
{
if (isEKM)
{
NumSrtucts = 9;
Size = sizeof(t_EEPROMImage);
}
else
{
NumSrtucts = 8;
Size = sizeof(t_EEPROMImage) - sizeof(t_ExtraMul1);
}
Offsets = new WORD [NumSrtucts];
Offsets[0] = offsetof(t_EEPROMImage, stHead1);
Offsets[1] = offsetof(t_EEPROMImage, stBPPS_Param1);
Offsets[2] = offsetof(t_EEPROMImage, stAdcGrad1);
Offsets[3] = offsetof(t_EEPROMImage, stTcorrCoef1);
Offsets[4] = offsetof(t_EEPROMImage, stKeyClb1);
Offsets[5] = offsetof(t_EEPROMImage, stItcUst1);
Offsets[6] = offsetof(t_EEPROMImage, stDACPar1);
Offsets[7] = offsetof(t_EEPROMImage, stDACGrad1);
if (isEKM)
Offsets[8] = offsetof(t_EEPROMImage, stExtraMul1);
}
~t_EEPROMOffsets()
{
delete[] Offsets;
}
WORD NumSrtucts;
WORD Size;
WORD* Offsets;
};
Answer the question
In order to leave comments, you need to log in
1) It's not C, but C++ (look at the question tag)
2) The number of structure fields cannot be variable. There are three of them: NumSrtucts, Size, Offsets.
3) Offsets is a pointer to which the heap-allocated memory is assigned in the constructor. And the size of this memory varies dynamically at the time the constructor is called, but this memory is stored outside the structure, and as it was said in the heap (dynamic memory), the structure only stores the address of this heap section in Offsets.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question