sizeof array of structure

Asked by yilmaz eyidogan


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;

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

 ((uint16_t *)&ulPar1),


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

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

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 :

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.