Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

difference between int* member[0] and int member[0] in struct

struct A {
  int zero_member[0];
  int other;
};

struct B {
  int* zero_member_ptr[0];
  int other;
};

printf("%d %d", sizeof(struct A), sizeof(struct B));

Output:

4 8

Why the difference?

In reality I’m using this with Android NDK, and I’ve tested it at Compiler Explorer without any flag. So, if this is not standard ISO C program, this problem should have no standard answer.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

"Why the difference?"

Likely due to padding to meet pointer alignment requirements – even if it is size 0.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading