sizeof array of structure

Asked by yilmaz eyidogan

Hi,

I cannot get sizeof structure array.

typedef struct{
 uint16_t * registerType;
 uint16_t * ptrU16; //r+w to same pointer
 uint16_t (*mbReadFuncPtr)(void);
 uint16_t (*mbWriteFuncPtr)(void);
 uint8_t orderOfRegister;
}ST_MODBUS_HOLDING_REGISTER_TYPE;

const ST_MODBUS_HOLDING_REGISTER_TYPE stHoldingRegArray[] = {
 {RW_U16_PTR_VAL,
 (uint16_t *)&ulPar1 + 1,
 rwDummyFunc,
 rwDummyFunc,
 START_OF_WORD_REGISTER},

 {RW_U16_PTR_VAL,
 ((uint16_t *)&ulPar1),
 rwDummyFunc,
 rwDummyFunc,
 END_OF_DWORD_REGISTER},

 {LAST_DUMMY_REGITER}
};

void getSize(void){
       uint16_t sizeOfHoldingRegister = sizeof(stHoldingRegArray)/sizeof(ST_MODBUS_HOLDING_REGISTER_TYPE);
}

Above sizeof operand causes this error:
invalid application of 'sizeof' to incomplete type 'const ST_MODBUS_HOLDING_REGISTER_TYPE[] {aka const struct <anonymous>[]}'

I couldn't find any solution. Could you please help?
I am using 2016q2 version of compiler for STM32F030 programming with Coocox software.

Thanks in advance.

Question information

Language:
English Edit question
Status:
Solved
For:
GNU Arm Embedded Toolchain Edit question
Assignee:
No assignee Edit question
Solved by:
yilmaz eyidogan
Solved:
Last query:
Last reply:
Revision history for this message
Thomas Preud'homme (thomas-preudhomme) said :
#1

Hi Yilmaz,

Can you provide a complete testcase, ie also provide the declaration of the types used in this example? Do you still have the error if removing the const keyword?

Best regards.

Revision history for this message
yilmaz eyidogan (yilmaz-eyidogan) said :
#2

Hello Thomas,

I have found my mistake. sizeof operand should be used after structure array. My main trunk is different from above code, so I couldn't catch the problem until I put here a note.

Thanks for your help.