473,389 Members | 1,119 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,389 software developers and data experts.

How can I peek at the assembly code generated by GCC -- Structure padding.

gcc -O2 -S -c b.c gives the answer but if we declare a structure say
struct test_t {
int a;
char b;
int c;
};
main()
{
struct test_t test= { 13,30, 40};
}

Now in command prompt if we type gcc -O2 -S -c b.c will give output in b.s file as
30 .align 4
31 .LC0:
32 0000 0D000000 .long 13
33 0004 1E .byte 30
34 0005 000000 .zero 3 ( structure padding of 3 Bytes)
35 0008 28000000 .long 40

with the help of gcc -S command we can see the padding done by compiler but if we don't

declare the structure say:

struct test_t {
int a;
char b;
int c;
};
main()
{
struct test_t test;/*= { 13,30, 40};*/
}

here the output is:
.LC0:
31 0000 256400 .string "%d"
32 .text
33 .align 4
35 .globl main
37 main:..


Here i can't see the structure, only if i assign the structure with a value then only "gcc

-S" is effective. Is their any other way to find padding done by structure.
Jul 2 '07 #1
2 1972
sicarie
4,677 Expert Mod 4TB
If you want to look at the assembly, you could use GDB - the GNU Debugger.
Jul 2 '07 #2
weaknessforcats
9,208 Expert Mod 8TB
You can calculate the pad yourself.
Expand|Select|Wrap|Line Numbers
  1. struct MyStruct
  2. {
  3.     int a;
  4.     char b;
  5.     int c;
  6. };
  7.  
Here the &a + (sizeof int) should be &b. If not, the difference between &a + (sizeof int) and &b is the pad.

You should find three pad bytes after b.

By &a + (sizeof int) I mean the &a plus (sizeof int) bytes.

You will need to convert your addresses to int to do the calculations.
Jul 2 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Bob Rock | last post by:
Hello, in the last few days I've made my first few attempts at creating mixed C++ managed-unmanaged assemblies and looking aftwerwards with ILDASM at what is visible in those assemblies from a...
13
by: Amarendra | last post by:
Folks, This structure padding issue is bothering me now, could not locate a satisfactory answer on clc, so here it goes... I have a structure, given below: typedef struct { int flag; char...
10
by: ranjeet.gupta | last post by:
Dear All !! Before i qoute my querry, I will like to qoute my analysis and my Knowledge Struct a { int raw; char data; };
28
by: kyle york | last post by:
Greetings, Why does the C standard require the members of a structure not be re-ordered (6.2.5.20)? Padding is allowed, and platform dependent, which means one cannot rely on the exact layout...
4
by: junky_fellow | last post by:
Can somebody please tell me about the structure alignment rules ? What I found was that on my system (cygwin running on PC, size of int=4 sizeof long=4, size of long long = 8) the cygwin compiler...
24
by: karthikbalaguru | last post by:
Hi, I find that the structure padding is not being taken into account while using 'new' operator. Is there a way to enable it ? struct Dataunit { char dataid; int keyid;
10
by: Rohit kumar Chandel | last post by:
Hi All, Please let me know how to find in a structure whether compiler has used padding or not. Regards Rohit
12
by: Kislay | last post by:
case 1 : struct s { char c1; // 8 double d; // 8 int i1; // 4 char c2; // 4 int i2; // 4 };
1
by: cnixuser | last post by:
Hello, I am having a problem that I believe is related to the way a stream reader object looks for a text file by default. What I am doing is using a StreamReader object to read the text of a text...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.