c - Why struct size is multiple of 8 when consist a int64 variable In 32 bit system -


in c programming language , use 32 bit system, have struct , struct size multiple of four. @ linker map file , size multiple of 8 example

typedef struct _str { u64 var1, u32 var2 } str; 

size of struct 16.

typedef struct _str { u32 var1, u32 var2, u32 var3 } str2; 

size of str2 12. working on 32 bit arm microcontroller. dont know why

the size of structure defined multiple of alignment of member largest alignment requirement. looks alignment requirement of u64 8 bytes in 32-bit mode on platform.

the following code:

#include <stdio.h> #include <stdint.h> int main() { printf("alignof(uint64_t) %zu\n", __alignof(uint64_t)); } 

produces same output when compiled in both 32-bit , 64-bit mode on linux x86_64:

alignof(uint64_t) 8 

Comments

Popular posts from this blog

WPF: binding viewmodel property of type DateTime to Calendar inside ItemsControl -

java - Getting corefrences with Standard corenlp package -

Java - Returning an array from a method to main -