top button
Flag Notify
    Connect to us
      Facebook Login
      Site Registration

Facebook Login
Site Registration

Why structure padding is done with 4 bytes irrespective to the 32bit or 64bit system?

+6 votes

Structure padding is useful for increasing processing speed for input/output, correct?
My question is i have tested structure padding on 32 and 64 bit system but both the place padding is done to achieve 4 Bytes jump, So why not 8 byte for 64 Bit system?

posted Apr 26, 2016 by Chirag Gangdev

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

+1 vote
Best answer

Thats not correct, most of C compilers have alignment requirement to every structure as largest member of the structure if it is more then int. i.e. if structure has members as char, int then alignment is 32 bits and if structure has members as char, int, double then alignment is 64bits on 64bit machine (32 on 32 bit machine).

For example try the following structure on 64bit machine

 char a,
 double b,
 int c

struct_t needs sizeof(char) + 7 byte padding + sizeof(double) + sizeof(int) = 1 + 7 + 8 + 4 = 20 bytes. However, the sizeof(struct_t) will be 24 bytes.

answer Apr 26, 2016 by Salil Agrawal
Similar Questions
+1 vote

I have some legacy binary code. Is there a way to run it on a current 64bit ubuntu system?

~$ file y
y: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.0.0, not stripped
~$ ./y
-bash: ./y: No such file or directory
+5 votes

What is structure padding and how it is used at processor level?

0 votes

I am thinking about converting my centos 6.3 32bit system to centos 6.4 64bit system. Please let me know what are the consequences of conducting this type of activity?

Contact Us
+91 9880187415
#280, 3rd floor, 5th Main
6th Sector, HSR Layout
Karnataka INDIA.