Skip to main content
BRoge
Associate
March 5, 2019
Question

Finding sizeof(structure) in Atollic TrueSTUDIO

  • March 5, 2019
  • 2 replies
  • 918 views

Hello,

I am programming a SMT32 chip and I am trying to find the size of a defined structure like the code snippet below. From reading online, using sizeof() on a structure can yield different results on different IDEs. When I use sizeof(struct some_struct) in Atollic TrueSTUDIO, I get an error. What do I use to return the size of a structure in Atollic TrueSTUDIO?

struct some_struct{
UINT8 variable1;
 
UINT8 variable2
 
UINT32 variable3
 
};
 
main(void){
UINT8 strucutre_size;
 
strucutre_size=sizeof(struct some_struct);
 
}

This topic has been closed for replies.

2 replies

Tesla DeLorean
Guru
March 5, 2019

What errors specifically does it report. Bunch of semi-colons missing if I cut-n-paste

typedef struct _some_struct{
 UINT8 variable1;
 
 UINT8 variable2;
 
 UINT32 variable3;
 
 } some_struct;
 
int main(void)
{
 size_t structure_size;
 
 structure_size = sizeof(some_struct);
 printf("%d\n", structure_size);
 
 while(1);
}

Tips, Buy me a coffee, or three.. PayPal VenmoUp vote any posts that you find helpful, it shows what's working..
Vangelis Fortounas
Associate II
March 5, 2019

Hello,

You missed some semicolons inside your structure, also the types UINTx may not be defined.

This code must work in True Studio.

   struct some_struct{

   uint8_t variable1;

   uint8_t variable2;

   uint32_t variable3;

   };

   int main(void){

   uint8_t structure_size;

   structure_size=sizeof(struct some_struct);

   }

"some_struct" is 32bit aligned, so after padding the total size reported from sizeof will be 8 bytes.

consider use #pragma pack(x) directive to change the alignment. and/or reorder structure members to reduce the requiring memory or to conform to some specific structure pack format.