473,387 Members | 1,420 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,387 software developers and data experts.

Compiler padded structure as output.

Is their any way to find compiler padded structure as output.
Ex:
struct{ int a; char b; int c;} ..
now after padding the structure will be
struct{ int a; char b;pad1; pad2; int c;}.. i actually want this as an output. Is it possible & how?
Jun 25 '07 #1
2 1258
Silent1Mezzo
208 100+
Is their any way to find compiler padded structure as output.
Ex:
struct{ int a; char b; int c;} ..
now after padding the structure will be
struct{ int a; char b;pad1; pad2; int c;}.. i actually want this as an output. Is it possible & how?
I'm pretty sure this isn't possible. You could find how much the compiler added in padding by doing sizeof(struct name);

You would just take that number and subtract the sizeof every individual item inside the struct.
Jun 25 '07 #2
weaknessforcats
9,208 Expert Mod 8TB
Create an object of your struct and take the address of each member.

If you have a char, the address of the next member subtracted from the address of the char member will give the pad on the char.

Expand|Select|Wrap|Line Numbers
  1. struct Test
  2. {
  3.    int a;
  4.    char b;
  5.    int c;
  6. };
  7. int main()
  8. {
  9.   Test obj;
  10.    int b = reinterpret_cast<int>(&obj.b);
  11.    int c = reinterpret_cast<int>(&obj.c);
  12.     cout << c - b << endl;
  13. }
  14.  
Visual Studio.NET shows c -b as 4. That is, the char occupies 4 bytes. Hence, there are 3 pad bytes after the char.
Jun 25 '07 #3

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

Similar topics

2
by: Stephen Horne | last post by:
I started making up a Python extension module to wrap a C++ library of mine using Boost Python. Trouble is, the library has a number of classes each of which has a lot of methods. I seem to have...
3
by: Tim Freeman | last post by:
Doing an independent study with Dave Beazley this quarter, Atul Varma has written a C compiler on his own in Python. It generates annotated x86 assembly code from arbitrary C files. Quoting...
2
by: yee young han | last post by:
I need a fast data structure and algorithm like below condition. (1) this data structure contain only 10,000 data entry. (2) data structure's one entry is like below typedef struct _DataEntry_...
0
by: John Dalberg | last post by:
I noticed that when I add key/value pairs to a NameValueCollection variable and send this collection through a POST using WebClient.UploadValues method, the recepient process receives the...
18
by: smnoff | last post by:
Ok, I am think I am a little more knowledgeable about C and pointers, ughh. And likewise, I want to fix C.....and not so much to make a C++ or Java or C# or even D like language. So, if I...
7
by: Eric Lilja | last post by:
Hello, I have an unsigned long that I need to convert to a std::string. The unsigned long holds 32-bit checksums and sometimes the most significant byte is 0 and in those cases the string should be...
9
by: fabio.bizzetti | last post by:
Hello all, I went across what seems possibly a bug of the compiler (VisualC 2005, just for the record) or a very strange and non-expected (by me at least) behaviour of the C++ ISO standard. Thus...
8
by: Chameleon | last post by:
I have a TGA image header struct. TGA has 18 bytes header, so the C struct too. why this return 20? sizeof(TGAHeader) I saw this in many structs. I believe compiler round up the size to 4...
61
by: dreamAnders | last post by:
ucc is an ANSI C Compiler. Its code size is about 15,000 lines. The lexer, parser and code generator are all hand-written. The code structure is very clear and straightforward. And there is an...
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...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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.